vue3中store分模块时其他vue页面中如何使用vuex中的actions mutations states


参考自:https://blog.csdn.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)
      }
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM