You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

37 lines
1.0 KiB

import {createStore} from "vuex";
import {moduleA} from "@/store/modules/ModuleA";
import {moduleB} from "@/store/modules/ModuleB";
export default createStore({
modules: {
module_a: moduleA,
module_b: moduleB,
},
state: {
count: 3,
},
getters: {
// getter使用箭头函数来定义,默认必传参数时state,如果需要其余参数,可以使用嵌套头函数
getter: (state) => (n) => {
return state.count * n;
},
},
mutations: {
// payload用于携带参数
mutation(state, payload) {
state.count += payload.num
}
},
actions: {
action(content, payload) {
// 模拟异步操作
setTimeout(() => {
// rep 模拟axios请求返回的数据
const rep = 3;
if (content.state.count > 50) {
content.commit('mutation', {num: rep + payload.num});
}
}, 1000)
}
}
})