通過v-if
的功能觸發(fā)頁面刷新隘马,結(jié)合provide
和inject
- 修改主文件
App.vue
原文件如下
<template>
<div id="app">
<router-view/>
</div>
</template>
<script>
export default {
name: 'App'
}
</script>
<style lang="less">
@import "./assets/css/app.css";
@import "./assets/css/time-range.css";
</style>
修改后的文件如下
<template>
<div id="app">
<router-view v-if="isRouterAlive"/>
</div>
</template>
<script>
export default {
name: 'App',
provide(){
return{
reload: this.reloadVue
}
},
data(){
return{
isRouterAlive: true
}
},
methods:{
reloadVue(){
this.isRouterAlive = false
this.$nextTick(function () {
this.isRouterAlive = true
})
}
}
}
</script>
<style lang="less">
@import "./assets/css/app.css";
@import "./assets/css/time-range.css";
</style>
- 在需要用到的主文件導(dǎo)入
export default {
name: "demo",
inject:['reload'],
data() {
return {
}
},
methods: {
reflesh(){
this.reload()
},
}
}