问题:
1.当我们在使用路由时,如果有导航条此时,我们在url地址栏目改变路由地址,此时路由内容更改但,导航条样式没有随着改动
2.当页面刷新时,url导航地址栏的路由和当前页面显示的不一致
3.当在页面中跳转页面时,导航条样式不变
解决:
1.通过watch监听路由地址的改变
2.使用钩子函数,改变路由
export default {
name: 'App',
data(){
return {
msg:'App.vue',
// 被激活的链接地址
currentRouter:'/'
}
},
methods:{
},
watch:{
'$route':function(to,from){
// to:跳转到的导航地址
this.currentRouter=to.path;
}
},
beforeMount(){
this.currentRouter=this.$route.path;
}
}