Vue问题解决方法合集

通过此文章来记录Vue实战项目中一些常见问题的解决方法。

vue-router 导航当前路由报错

1
message: "Navigating to current location (XXX) is not allowed"

我们可以通过重写路由的push方法来解决此问题。

1
2
3
4
5
6
//import Router from "vue-router"

const routerPush = Router.prototype.push
Router.prototype.push = function push(location) {
return routerPush.call(this, location).catch(error=> error)
}