例如:name值改變重新請求接口疏虫,頁面沒有更新
localhost:8088/#/index?name=Susan
localhost:8088/#/index?name=Marry
解決:在 app.vue中添加 key:
<div id="app" :key="appKey">
<router-view v-if="isRouterAlive"></router-view>
</div>
data: function () {
return {
isRouterAlive: true,
appKey:1,
}
},
watch:{
'$route':function(newUrl,oldUrl){
this.appKey=new Date().getTime();
}
},
添加了Key值,帶參改變后啤呼,頁面視圖也會重新渲染