vue跳转当前页面不刷新问题
程序员文章站
2022-07-12 19:10:43
...
利用provide 和inject 解决:vue跳转当前页面不刷新问题
App.vue
<template>
<div id="app">
<router-view v-if="isRouterAlive" ref="route" />
</div>
</template>
<script>
export default {
name: 'App',
provide() {
return {
reload: this.reload
}
},
data() {
return {
isRouterAlive: true
}
},
methods: {
reload() {
this.isRouterAlive = false
this.$nextTick(function() {
this.isRouterAlive = true
})
}
}
}
</script>
要引用的界面
// 第一步:引入
inject: ['reload'],
// 第二步: 调用
this.reload()