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.
 
 
 

34 lines
951 B

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