vue2不能使用vue-router4.0版本

说明

最近复习一篇关于 springboot+vue 前后端交互的案例 , 主要是前端比较重要

参考的文章是:

https://mp.weixin.qq.com/s/rGxKH-Zibp8QH30clZ1cLg

情景在线

我是用 vue ui 构建 vue-cli 脚手架 , 基于 vue2 , 选项默认

使用 npm 手动 安装 vue-router

发现 vue-router 不能使用

具体版本 , 见 package.json 文件

  "dependencies": {
    "axios": "^0.26.1",
    "core-js": "^3.6.5",
    "vue": "^2.6.11",
    "vue-router": "^4.0.14",
    "vuex": "^4.0.2"
  },

解决方案

更换 vue-router 版本 为 3.x 版本

修改后 package.json

  "dependencies": {
    "axios": "^0.26.1",
    "core-js": "^3.6.5",
    "vue": "^2.6.11",
    "vue-router": "^3.0.6",
    "vuex": "^4.0.2"
  },

到此 vue-router 可以使用

补充

因为我对 vue 掌握成都就是在大概了解

所以 我看了一下 vue-router 官网

官网提示 3.x 和 4.x 稍微有点区别

参考网址:

https://router.vuejs.org/zh/guide/migration/index.html

总结

vue2 要是用 vue-router 的 3.x 版本 , 否者会出现无法使用情况

Logo

前往低代码交流专区

更多推荐