VUE页面刷新
window.location.reload()
this.$router.go(0)
以上这两种方法是会出现一瞬间的白屏,并且不会实现页面数据同步更新。
要同步实现页面数据更新(不会重新刷新页面),同时保证有分页时,能够停留在当前页
- 在app.vue的加上v-if属性
在data里面加上isRouterAlive,当然这个属性名可以自己定义,默认值为true
data () {
return {
isRouterAlive: true
}
}
methods里面加入一个刷新的方法
methods: {
reload () {
this.isRouterAlive = false
this.$nextTick(function() {
this.isRouterAlive = true
})
}
}
最后,需要把这个函数 provide 出去
provide () {
return {
reload: this.reload
}
}
需要刷新的时候,注入这个函数,然后在需要用到这个函数的地方去引用就行了
refresh () {
this.reload()
}
引自:https://www.jianshu.com/p/b6d7db35b6e4