vue刷新当前页面(不会出现闪屏)
父子组件传值 也可以在父组件完成所有的操作 不需要到子组件
1. 在app.vue的加上v-if属性
<router-view v-if="isRouterAlive"></router-view>
2. 在data里面加上isRouterAlive,当然这个属性名可以自己定义,默认值为true
data () {
return {
isRouterAlive: true
}
}
3.methods里面加入一个刷新的方法
methods: {
reload () {
this.isRouterAlive = false
this.$nextTick(function() {
this.isRouterAlive = true
})
}
}
4.最后,需要把这个函数 provide 出去 (跟data同级)
provide () {
return {
reload: this.reload
}
}
这样,app.vue上就设置完了
那么当我们需要刷新的时候,在需要的页面上加上这个函数就可以了
5.首先注入这个函数
inject: ['reload'] (跟data同级)
6. 然后在需要用到这个函数的地方去引用就行了
refresh () {
this.reload()
}