更改路由器路径

时间:2019-08-11 23:34:47

标签: javascript vue.js

我正在尝试在调用函数时更改路由器:

register() {
  if (this.password === this.confirmPass) {
    this.submit = true
    this.active = true
    this.errorMessage = ''
    this.$emit('user-added', userName)
    ;('some code here to change the route')
  } else {
    this.errorMessage = 'password does not match!'
  }
}

2 个答案:

答案 0 :(得分:1)

如果您使用的是vue-router,则可以像这样this.$router.push('/some-route')更改路由,也可以使用路由名this.$router.push({ name: 'nameOfRoute' })

答案 1 :(得分:0)

您可以使用router.push('home')来更改路线之间的切换。

相关问题