Vue-router钩子在路径变化时无法生效。
发布于 7 年前 作者 BubblyFace 4255 次浏览 来自 问答

有一些组件想根据路径变化进行选择展示。但路由的钩子无法生效。 我测试了API的两个钩子。

beforeRouteEnter(to, from, next) {
            next(vm => {
                vm.init()
            })
        },
        beforeRouteUpdate(to, from, next) {
            next(vm => {
                vm.init()
            })
        },

判断函数写在了init函数中。

init() {
                //接受ablumItem选择显示页面
                var params = this.$route.params;
                this.show[params.ablumItem] = true;

            },

为什么钩子函数只在第一次进入组件时生效。

回到顶部