Vue中相同路由,带不同参数,请求接口后页面视图不更新
2019-12-25 本文已影响0人
胡自鲜
例如: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值,带参改变后,页面视图也会重新渲染