存在嵌套且命名空间存在
namespaced:true存在
modules:{
模块名字:{
namespaced:true,
state:()=>({}),
getters:{},
mutions:{},
actions:{}
}
}
映射关系的使用
state如何使用 使用的时候直接使用属性名
...mapState("模块名字",["属性名"])
...mapState({
属性名:(state)=>state.模块名.属性名
})
getters 直接使用方法名
...mapGetters(["模块名字/方法"])
...mapGetters({
方法:(state)=>state.模块名.方法
})
mutions如何使用 直接使用方法名
...mapMutations(["模块名字/方法"])
...mapMutations({
方法:(state)=>state.模块名.方法
})
actions 直接使用方法名
...mapActions(["模块名字/方法名"])
...mapActions({
方法:(state)=>state.模块名.方法
})
存在嵌套且命名空间不存在
namespaced:false 或者就没写这个属性
modules:{
模块名字:{
state:()=>({}),
getters:{},
mutions:{},
actions:{}
}
}
映射关系的使用
state如何使用 使用的时候直接使用属性名
...mapState({
属性名:(state)=>state.模块名.属性名
})
getters 直接使用方法名
...mapGetters(["方法"])
...mapGetters({
方法:"方法名"
})
mutions如何使用 直接使用方法名
...mapMutations(["方法"])
...mapMutations({
方法:"方法名"
})
actions 直接使用方法名
...mapActions(["方法名"])
...mapActions({
方法:"方法名"
})
存在嵌套存在命名空间全局和局部混用和方法和属性重命名
namespaced:true存在
modules:{
模块名字:{
namespaced:true,
state:()=>({}),
getters:{},
mutions:{},
actions:{}
}
}
映射关系的使用
🌰state如何使用 使用的时候直接使用属性名
...mapState("模块名字",["属性名"])
...mapState("模块名字",{
名字:属性名字
})
...mapState({
属性名:(state)=>state.模块名.属性名, //模块属性
属性名:(state)=>state.属性 //全局属性
})
🌰getters 直接使用方法名
...mapGetters(["模块名字/方法"])
...mapGetters("模块名",{
方法:"方法名"
})
...mapGetters({
方法:(state)=>state.模块名.方法, //模块方法
方法:(state)=>state.方法 //全局方法
})
🌰mutions如何使用 直接使用方法名
...mapMutations(["模块名字/方法"])
...mapMutations("模块名",{
方法:"方法名"
})
...mapMutations({
方法:(state)=>state.模块名.方法, //模块方法
方法:(state)=>state.方法 //全局方法
})
🌰actions 直接使用方法名
...mapActions(["模块名字/方法名"])
...mapActions("模块名",{
方法:"方法名"
})
...mapActions({
方法:(state)=>state.模块名.方法, //模块方法
方法:(state)=>state.方法 //全局方法
})
属性或者方法的重命名 mapGetters mapMutations mapActions 同理 举个🌰mapState的
...mapState({
属性名(可赋值为和state属性名不同的字符串):(state)=>state.模块名.属性名, //模块属性
属性名(可赋值为和state属性名不同的字符串):(state)=>state.属性
})