zoukankan      html  css  js  c++  java
  • vue踩坑--TypeError: __WEBPACK_IMPORTED_MODULE_1_vuex__.a.store is not a constructor

    今天在使用vuex的时候遇到这么个问题,虽然后来解决了,是首字母大写的原因,但我还是不知道为什么。这里先记录下来。


    这是vuex/store.js

    import Vue from 'vue'
    import Vuex from 'vuex'
    
    Vue.use(Vuex)
    
    const state = {
        count: 1
    }
    
    export default new Vuex.store({
        state
    })

    控制台报错TypeError: __WEBPACK_IMPORTED_MODULE_1_vuex__.a.store is not a constructor
    TypeError: "x" is not a constructor里的解释:

    是因为尝试将不是构造器的对象或者变量来作为构造器使用。参考 constructor 或者 new operator 来了解什么是构造器。

    另在网上找到博客一篇,之处这是因为Store的S小写了。

    这个报错的是_vuex2.default.store 不是一个构造函数因为在我们用vuex的时候需要将用到的actions,mutations模块最终导出,在导出的时候new Vuex.Store中的Store小写了,这里的一定要大写,就相当于我们在使用构造函数(类)的时候首字母要大写

  • 相关阅读:
    Docker
    Docker
    Docker
    Docker
    Docker
    Docker
    pandas——向已经存在的excel数据写入data
    python——利用UI选择路径
    python——装饰器的使用
    python——生成器(协程)gevent多任务
  • 原文地址:https://www.cnblogs.com/ZaraNet/p/9900869.html
Copyright © 2011-2022 走看看