未捕获的类型错误:(0, vue__WEBPACK_IMPORTED_MODULE_20__.reactive) 不是一个函数 - 在 Vue 2 中

问题描述 投票:0回答:2

我是 Vue js 的新手,

控制台错误:

Error

Uncaught TypeError: (0 , vue__WEBPACK_IMPORTED_MODULE_20__.reactive) is not a function - in Vue 2
    at resetStoreState (webpack-internal:///./node_modules/vuex/dist/vuex.esm-bundler.js:221:64)
    at new Store (webpack-internal:///./node_modules/vuex/dist/vuex.esm-bundler.js:1031:3)
    at eval (webpack-internal:///./src/store/index.js:7:13)
    at Module../src/store/index.js (app.js:186:1)
    at __webpack_require__ (app.js:268:33)
    at fn (app.js:513:21)
    at eval (webpack-internal:///./src/main.js:12:70)
    at Module../src/main.js (app.js:175:1)
    at __webpack_require__ (app.js:268:33)
    at app.js:1385:109

我已在此处附上图片:https://postimg.cc/FfVC6dmw

=> 我安装了 Vuex 并在 src 文件夹中创建了一个文件夹,并在其中创建了 index.js文件写入代码如下:


    从“vue”导入 Vue;
    从 'vuex' 导入 Vuex;
    
    Vue.use(Vuex);
    
    const store = new Vuex.Store({
        状态:{
            消息:“你好,来自 Vuex”
        },
        突变:{},
        操作:{},
        吸气剂:{}
    
    })
    
    导出默认存储;

=>Main.js


    从“vue”导入 Vue
    从“./App.vue”导入应用程序
    从 './store/index' 导入 StoreC
    
    Vue.config.生产提示 = false
    
    新的Vue({
        商店C,
        渲染:h => h(应用程序),
    }).$mount('#app')


我在下面附上了package.json。


    {
      “名称”:“vuex-shop”,
      “版本”:“0.1.0”,
      “私人”:真实,
      “脚本”:{
        "serve": "vue-cli-service 服务",
        "build": "vue-cli-service 构建",
        "lint": "vue-cli-service lint"
      },
      “依赖项”:{
        "core-js": "^3.8.3",
        "vue": "^2.6.14",
        “vuex”:“^4.0.2”
      },
      “开发依赖项”:{
        "@babel/core": "^7.12.16",
        "@babel/eslint-parser": "^7.12.16",
        "@vue/cli-plugin-babel": "~5.0.0",
        "@vue/cli-plugin-eslint": "~5.0.0",
        "@vue/cli-service": "~5.0.0",
        "eslint": "^7.32.0",
        "eslint-plugin-vue": "^8.0.3",
        “安装对等点”:“^1.0.3”,
        “vue-模板编译器”:“^2.6.14”
      },
      “eslint配置”:{
        “根”:正确,
        “环境”:{
          “节点”:真
        },
        “延伸”:[
          “插件:vue/essential”,
          “eslint:推荐”
        ],
        “解析器选项”:{
          “解析器”:“@babel/eslint-parser”
        },
        “规则”:{}
      },
      “浏览器列表”:[
        > 1%”,
        “最后两个版本”,
        “没死”
      ]
    }

javascript vue.js vuejs2 vuex
2个回答
3
投票

您的 Vue 版本与您的 Vuex 版本不兼容。

Vuex 3 可与 Vue 2 配合使用:https://v3.vuex.vuejs.org/

Vuex 4 可与 Vue 3 配合使用:https://vuex.vuejs.org/

您特别需要:

npm install [email protected]


0
投票
  1. 检查 Vuex 版本:确保您使用的 Vuex 版本适合您的 Vue.js 版本。 Vuex 4.x 是为 Vue 3 设计的,而 Vuex 3.x 是为 Vue 2 设计的。如果您使用的是 Vue 2,请确保安装了 Vuex 3.x。

    npm 安装 vuex@3

  2. 如果您仍然遇到此问题:dist 文件夹中仍然缺少 vuex.esm-bundler.js,我认为有时清除节点模块并重新安装会有所帮助

祝你好运

© www.soinside.com 2019 - 2024. All rights reserved.