真实的业务场景中,这种情况很多。比如

页面切换时不会触发mounted钩子,解决方法在router-view上加上一个唯一的key,来保证路由切换时都会重新渲染触发钩子了。

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

: computed: {
    key() {
        return this.$route.name !== undefined? this.$route.name + +new Date(): this.$route + +new Date()
    }
}
复制代码

前端菜鸟写笔记(非原创)欢迎点赞。

Logo

前往低代码交流专区

更多推荐