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