美文网首页
vue 实现 reload 功能

vue 实现 reload 功能

作者: 乐观的猴 | 来源:发表于2019-08-03 20:40 被阅读0次
    1. App.vue ( 主组件) 配置代码
    1. 声明一个变量
      data () {
        return {
          isRouterAlive: true
        }
      },
    2. 定义一个方法
      methods: {
        reload () {
          this.isRouterAlive = false;
          this.$nextTick(function () {
            this.isRouterAlive = true;
          })
        }
    }
    3. provide 选项允许我们指定我们想要提供给后代组件的数据/方法
    export default {
      name: 'App',
      provide () {
        return {
          reload: this.reload
        }
      }
    }
    
    4. 最后一步, 在 router-view 上加入 isRouterAlive
    <template>
      <div id="app" @click="clicked">
        <router-view v-if="isRouterAlive" ref="route"/>
      </div>
    </template>
    
    
    1. 子组件 Custom.vue (需要reload 的子组件), 配置代码
      export default {
        inject: ['reload']
    }
    
      methods: {
            refresh: function () {
                  // 业务代码, bala ...
    
                  this.reload();
                
             }
        }
    }
    
    

    相关文章

      网友评论

          本文标题:vue 实现 reload 功能

          本文链接:https://www.haomeiwen.com/subject/dkfdrctx.html