您当前的位置: 首页 >  ide

暂无认证

  • 0浏览

    0关注

    92582博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

vue、uniApp、刷新页面、更新、强制、命令、provide、inject

发布时间:2021-12-04 17:47:41 ,浏览量:0

目录
  • 1、原生方法
  • 2、vue自带的方法
  • 3、自定义全局刷新方法
1、原生方法
location.reload(); 
2、vue自带的方法

路由跳转

this.$router.go(0); 

强制刷新API

此API也适用于uniApp,亲测有效。

this.$forceUpdate(); 
3、自定义全局刷新方法

App.vue文件

<template> <div id="app"> <router-view v-if="isRouterAlive"> name: 'App', // 父组件中通过provide来提供变量, // 在子组件中通过inject来注入变量 provide () { return { reload: this.reload }; }, data() { return { // 控制视图是否显示的变量 isRouterAlive: true }; }, methods: { reload () { // 先关闭 this.isRouterAlive = false; this.$nextTick(function () { // 再打开 this.isRouterAlive = true; }); } } }; 

使用

export default { // 注入App里的reload方法 inject: ['reload'], data () { return { } }, mounted() { // 使用 // 也可以是点击触发 this.reload(); }, methods:{ } }; 
关注
打赏
1653961664
查看更多评论
立即登录/注册

微信扫码登录

0.5426s