vue刷新当前路由 router-view中的内容

通过改变router-view中的key来达到刷新组件的目的。

<span class="refresh" title="刷新" @click="refresh">
    <i class="iconfont"></i>
</span>

<router-view :key="activeDate" />

界面上有个刷新按钮,点击刷新的时候,执行函数,改变activeDate的值,为当前的时间戳。这样就会刷新router-view中的内容。

data() {
    return {
      activeDate: 1
    }
},
methods: {
    refresh() {
      this.activeDate = new Date().getTime()
    }
}

猜你喜欢

转载自www.cnblogs.com/2018cd/p/9106327.html