VUE 实现局部刷新
gyh 2018-09-09
我们可以利用 Vue 里面的 provide+inject 组合
首先需要修改 App.vue
//App.vue <template> <div id="app"> <div> <router-view v-if="alive" /> </div> </div> </template> <script> export default { name: 'App', provide() { return { reload: this.reload } }, data() { return { alive: true } }, methods: { reload() { this.alive= false this.$nextTick(() => { this.alive = true }) } } } </script>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31其次到需要刷新的页面进行引用
使用 inject 导入引用 reload
inject: ['reload'], this.reload()
1
2