html
复制代码
<template>
<div id="app">
<router-view v-if="routerAlive"></router-view>
</div>
</template>
javascript
复制代码
export default {
//暴露 reload 这个方法,方便组件调用
provide() {
return {
reload: this.reload,
}
},
data() {
return { routerAlive: true }
},
methods: {
//重新加载的方法
reload() {
this.routerAlive = false
this.$nextTick(function () {
this.routerAlive = true
})
},
},
}
javascript
复制代码
export default {
inject: ["reload"],
......
methods:{
handleReload(){
//在你要用到的地方调用这个重新刷新的方法
this.reload()
}
}
}
javascript
复制代码
// 1.window.location.reload()应该是刷新.相当于 按页面刷新按钮
window.location.reload()