vue跳轉當前頁面不刷新問題
provide / inject 組合 方式是最實用的,首先我們要修改APP.vue
<template>
<div id="app">
<router-view v-if="isRouterAlive" />
</div>
</template>
<script>
export default {
name: "App",
provide(){
return{
reload:this.reload
}
},
data() {
return {
isRouterAlive:true
};
},
methods:{
reload(){
this.isRouterAlive=false;
this.$nextTick(()=>{
this.isRouterAlive=true
})
}
}
}
</script>
通過聲明reload方法,控制router-view的顯示或隱藏,從而控制頁面的再次加載,這邊定義了
isRouterAlive //true or false 來控制
然后在需要當前頁面刷新的頁面中注入App.vue組件提供(provide)的 reload 依賴,然后直接用this.reload來調用就行
使用頁面
watch: {
'$route' (to, from) {
// 對路由變化作出響應...
this.routerParms.list=to.query.list
this.reload()
},
}