美文网首页
Vue中相同路由,带不同参数,请求接口后页面视图不更新

Vue中相同路由,带不同参数,请求接口后页面视图不更新

作者: 胡自鲜 | 来源:发表于2019-12-25 19:05 被阅读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值,带参改变后,页面视图也会重新渲染

相关文章

网友评论

      本文标题:Vue中相同路由,带不同参数,请求接口后页面视图不更新

      本文链接:https://www.haomeiwen.com/subject/wnfhoctx.html