vuex传参------

index.js

import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);

const store = new Vuex.Store({
    state: {
        use: "gao",
        num: 2
    },
    mutations: {
        tongChange(state, n) {
            state.use = n
        },
        tongNum(state) {
            state.num += 1
        },
        //异步 不推荐
        yibuNum(state) {
            setTimeout(() => {
                state.num += 1
            }, 3000)
        }
    },
    getters: {
        updateNum(state) {
            return state.use.toUpperCase()
        }
    },
    actions: {
        actionTongNum({
            commit
        }) {
            commit("tongNum")
        },
        actionYiNum({
            commit
        }) {
            setTimeout(() => {
                commit("tongNum")
            }, 500)
        }
    }




})

export default store;

state.



getters



Mutations



Actions



你可能感兴趣的:(前端)