VUE - vuex的...map使用合集

App.vue

state.js

export default {
    arr:[]
}

getters.js

export default {
    getterArr(state) {
        return state.arr.map(value => value * 2);
    }
}

mutations.js

import {ARRCRE, ARRDEL, ARRUPD} from './mutation-types'
export default {
    [ARRCRE](state, payload){
        state.arr.push(payload);
    },
    [ARRDEL](state, payload){
        state.arr.splice(payload, 1)
    },
    [ARRUPD](state, payload){
        state.arr.splice(payload.s, 1, payload.d)
    }
}

actions.js

import {ARRUPD, ARRDEL, ARRCRE} from "./mutation-types";
export default {
    dataC(context, payload) {
        context.commit(ARRCRE, payload);
    },
    dataD(context, payload) {
        context.commit(ARRDEL, payload);
    },
    dataU(context, payload) {
        context.commit(ARRUPD, payload);
    }
}

mapState三种写法



mapMutations三种写法


你可能感兴趣的:(VUE - vuex的...map使用合集)