vue不刷新页面更新数据

在App.vue中

 1 <template>
 2   <div id="app">
 3     <router-view v-if="isRouterAlive"/>
 4   </div>
 5 </template>
 6 
 7 <script>
 8   export default {
 9     name: 'App',
10     provide: function () {
11       return {
12         reload: this.reload
13       }
14     },
15     data: function () {
16       return {
17         isRouterAlive: true
18       }
19     },
20     methods: {
21       reload: function () {
22         this.isRouterAlive = false;
23         this.$nextTick(function () {
24           this.isRouterAlive = true
25         })
26       }
27     }
28   }
29 </script>

然后在需要使用这个方法的的vue组件中注入这个方法

1 data(){},
2 inject:["reload"]
3 
4 
5 //然后在你想要使用的地方 使用就可以了
6 this.reload()

转自:https://www.jianshu.com/p/26d37a1d5b73

猜你喜欢

转载自www.cnblogs.com/ronle/p/10852684.html