在store中的模块化下使用:
import store from '../index'
import { ElNotification } from 'element-plus'
const state = {
userInfo: '',
}
const mutations = {
setState(state, { key, obj }) {
state[key] = { ...obj }
}
}
const actions = {
async login({ commit }, obj) {
post(xxx, obj).then(
(res) => {
console.log(res)
}
)
},
logout({ commit }) {
}
}
export default {
state,
mutations,
actions,
namespaced: true, //使用时加上父级名
}
调用异步action的语法:
store.dispatch('父级名/login', params)