Vue-路由使用

版权声明:草原上的雄鹰 https://blog.csdn.net/sinat_36729274/article/details/81506828

一.路由获取

let id = this.$route   :获取当前的路由

let activityId=this.$route.query.activityId;  :获取路由中的参数 activityId

二.路由监听

1.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);

  }

}

猜你喜欢

转载自blog.csdn.net/sinat_36729274/article/details/81506828