美文网首页
Vue路由监听变化

Vue路由监听变化

作者: Cherry丶小丸子 | 来源:发表于2019-12-06 09:43 被阅读0次

方法一:通过 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);
    }
}

相关文章

网友评论

      本文标题:Vue路由监听变化

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