刷新页面
方法一window.reload();
方法二
this.$router.go(0);
以上两种方式会出现白屏
方法三不会有闪烁的空白出现 App.vue
export default {
name: 'App',
// 暴露reload,方便后面组件调用
provide(){
return {
reload: this.reload
}
},
data(){
return {
isRouterAlive: true
}
},
methods:{
// 重新加载方法
reload(){
this.isRouterAlive = false;
this.$nextTick(()=>{
this.isRouterAlive = true;
})
}
}
}
子组件调用刷新方法
export default {
// 获取APP.vue里的reload方法
inject: ["reload"],
methods: {
reloadPage() {
// 刷新页面
this.reload();
}
}
}
参考 vue项目如何刷新当前页面