Vue路由监听变化

2019-12-06  本文已影响0人  Cherry丶小丸子

方法一:通过 watch

// 监听,当路由发生变化的时候执行
watch:{
    $route(to,from){
        console.log(to.path);
    }
}

// 监听,当路由发生变化的时候执行
watch: {
    $route: {
        handler: function(val, oldVal){
            console.log(val);
        },
        // 深度观察监听
        deep: true
    }
}

// 监听,当路由发生变化的时候执行
watch: {
    '$route':'getPath'
},
methods: {
    getPath(){
        console.log(this.$route.path);
    }
}
上一篇 下一篇

猜你喜欢

热点阅读