vue中遇到的报错

博客分类: 笔记 阅读次数: comments

vue中遇到的报错

Uncaught TypeError: __WEBPACK_IMPORTED_MODULE_1_vuex__.a.store is not a constructor

vue中报这个错,说明在vuex的暴露中export default new Vuex.Store的Store的s没有大写,原因不清楚,估计这是人家定义好的东西就跟什么变量名啊之类的定义规则一样

今天在跟着视频写豆瓣联系时发现了在重复点击 router-link 会造成报错的问题, 报错内容为:

Uncaught (in promise) NavigationDuplicated {_name: "NavigationDuplicated", name: "NavigationDuplicated", message: "Navigating to current location ("/index") is not allowed", stack: "Error↵    at new NavigationDuplicated (webpack-int…_modules/_vue@2.6.10@vue/dist/vue.esm.js:2187:14)"}

解决方法很简单,把项目依赖的 node_modules 文件夹删除, 然后再 npm install 重新下载依赖包就可以解决。(我没有测试,我用的是下面的方法,不需要更换route版本)

发现以上方法很多人都不能成功解决,经过多次尝试发现原因可能是 在重新下载依赖包时,安装的vue-router还是之前出错的那个版本,那么要怎么解决呢?解决方法也很简单,在项目目录下运行 npm i vue-router@3.0 -S 即可

如果不想换 vue-router 的版本 或者 还是 没有用,那么可以用以下方法 在main.js下添加一下代码:

import Router from 'vue-router'

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

原文链接:https://blog.csdn.net/weixin_43202608/article/details/98884620