一、watch監(jiān)聽路由的方法
通過watch監(jiān)聽,當(dāng)路由發(fā)生變化的時候執(zhí)行。
方法一:
watch:{ $router(to,from){ console.log(to.path) } }
方法二:
watch: { $route: { handler: function (val, oldVal){ console.log(val); }, // 深度觀察監(jiān)聽 deep: true } },
方法三:
watch: { '$route' : 'getPath' }, methods: { getPath(){ console.log( this .$route.path); } }