在使用vuex时遇到的坑

坑一:

使用vuex有时会报如下的错误

here are multiple modules with names that only differ in casing.
This can lead to unexpected behavior when compiling on a filesystem with other case-semantic.
Use equal casing. Compare these module identifiers

这是因为你引入vuex的时候有的地方首字母大写,有的地方首字母小写导致的,如下:

test1.vue这样引入

import {mapState,mapGetters,mapMutations,mapActions} from 'vuex'

在main.js又这样引入,注意划线部分大写了

import Vuex from 'Vuex';

总结:引入的时候,要么全首字母大写,要么全小写,否则会报以上错误

坑二:

当模块化vuex(及,使用它的modules属性)时,如下代码划线部分,在子模块中有一些state

import * as types from '../mutation-types'

const state={
	sWorkType:'你没选任何东西'
}


export default {
	state
}
在组件中这样的写法直接访问是访问不到的,如下代码

computed:{
            ...mapState([
                'sWorkType'
            ])
        },
        created(){
            console.warn(this.sWorkType)
        },
必须下面的方法才能访问到state,不知道为何,但奇怪的是getters又可以用上述方法访问

computed:{
            ...mapState([
                'sWorkType'
            ])
        },
        created(){
            console.warn(this.$store.state.orderDetail.sWorkType)
        },





评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值