vue3中store分模块时其他vue页面中如何使用vuex中的actions mutations states
参考自:https://blog.****.net/qq_47452289/article/details/111944935
store/account.js
const state={ userName: null } const actions = { login({commit}, userinfo){ return new promise( (resolve, reject) => { loginByUserName(userinfo.userName, userinfo.password).then(res => { }) } ) } } const mutations = { setAccount ( state, data ) { state.username = data.username } } export default { state, actions, mutations, namespaced: true }
vue文件中使用
import { mapActions} from "vuex" methods: { ...mapActions("account",["login"]), //映射account模块中的login方法 submit(){ this.login(userInfo) } }