如果在script中控制vue-router的跳转

想要在一个点击的回调函数中跳转路由,应该怎么写?this.$route上好像没有实例方法,那怎么能获取到router的实例呢?

阅读 4.9k
5 个回答
this.$router.push({
    path: 'xxx'
})
new Vue({
  el: '#app',
  router,       //这里注入到了Vue实例上吗
  template: '<App/>',
  components: { App }
})

获取路由信息用this.$route
获取router用this.$router

this.$router.push({ path: '' });//跳转到该路由

this.$router.go(-1);//后退

this.$router.push({name: '', params: {}})

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题