mapState和mapMutation的基本使用方法
import{mapState}from'vuex'exportdefault{computed: {// 日常写法account() {returnthis.$store.state.account},password() {returnthis.$store.state.password},age() {returnthis.$store.state.age},other:() =>"other"},computed: {// 子模块的属性因有了命名空间 无法直接使用数组 magic// mutations 是没有的 可以看下文...mapState({userName:state=>state.user.name,userAge:state=>state.user.age})// magic style1...mapState(['account','password','age']),other:() =>"other"},computed: {// magic style2 自定义属性法名...mapState({account:'account',password:'password',age:'age', }),other:() =>"other"},computed: {// magic style3 更多灵活处理...mapState({account:(state) =>{// account: state => state.account | account(state) {} returnstate.account},password:(state) =>{// password: state => state.age | password(state) {}returnstate.password},age:(state) =>{// age: state => state.age | age(state) {} returnstate.age} }),other:() =>"other"} }