美文网首页
2020-02-17 用provide / inject解决vu

2020-02-17 用provide / inject解决vu

作者: Rockage | 来源:发表于2020-02-17 04:54 被阅读0次

要点:

  1. app.vue
//模板:
   <router-view  v-if="isRouterAlive"></router-view>
//Vue代码:
export default {
  name: "App",
data() {
  return {
    isRouterAlive: true
  };
},
provide() {
  return {
    reload: this.reload
  };
},
methods: {
  reload: function() {
    this.isRouterAlive = false;
    this.$nextTick(function() {
      this.isRouterAlive = true;
    });
  },
};
  • 任何需要调用reload()的子组件中:
    export default {
    name: "bbs",
    inject: ["reload"],
    
  • 在这个子组件中,通过this.reload()来刷新页面。

相关文章

网友评论

      本文标题:2020-02-17 用provide / inject解决vu

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