1.简单方法
this.$router.go(0)
location.reload()
2.实用方法
用到 provide / inject 组合
①首先修改app.vue文件,编辑内容如下:
<template>
<div id="app">
<router-view v-if="isRouterAlive" />
</div>
</template>
<script>
export default {
name: 'App',
data () {
return {
isRouterAlive: true
}
},
methods: {
//通过声明reload方法,控制router-view的显示或隐藏,从而控制页面的再次加载
reload () {
this.isRouterAlive = false
this.$nextTick(function () {
this.isRouterAlive = true
})
}
},
provide () {
return {
reload: this.reload
}
}
}
</script>
②在需要当前页面刷新的页面中注入App.vue组件提供(provide)的 reload 依赖,直接用this.reload调用