1、传统方法
window.location.reload();
2、router方法
this.$router.go(0);
前面两种方式是强制刷新页面,会有短暂的闪烁。。。
优化如下:
App.vue
export default {
name: 'App',
provide() {
return {
reload: this.reload
}
},
data() {
return {
isRouterAlive: true
}
},
methods: {
reload() {
this.isRouterAlive = false;
this.$nextTick(function() {
this.isRouterAlive = true;
})
}
}
}
然后在需要用到的地方调用即可
inject: ['reload']
this.reload();
网友评论