vue-router ---- 解决页面刷新和路由改变时导航条样式问题

版权声明:版权声明:本文为博主原创文章,若文章中有错误请联系博主改正,请不要恶意留言(不喜欢请绕道)。欢迎大家转载 https://blog.csdn.net/qq_37674616/article/details/83576798

问题:

  1.当我们在使用路由时,如果有导航条此时,我们在url地址栏目改变路由地址,此时路由内容更改但,导航条样式没有随着改动

  2.当页面刷新时,url导航地址栏的路由和当前页面显示的不一致

解决:

 1.通过watch监听路由地址的改变

 2.使用钩子函数,改变路由

  export default {
    name: 'App',
    data(){
      return {
        msg:'App.vue',
        currentRouter:'/'
      }
    },
    methods:{
     
    },
    watch:{
      '$route':function(to,from){
          this.currentRouter=to.path;
      }
    },
    beforeMount(){
        this.currentRouter=this.$route.path;
    }
  }

**: 上面的代码,要放在跟路由页面中

猜你喜欢

转载自blog.csdn.net/qq_37674616/article/details/83576798