How does vuex store the requested data into store in a public js?

topic description

when writing a vue project, using vuex, I now encapsulate the public methods into a separate js file. When requesting a background interface, how do I store the requested data in store?

related codes

import store from "@/store"
async getUserInfo () { // 
    try {
      let user = await getUser()

      // store.default.dispatch("user/USER_GET_INFO", user)
      // 

      return user
    } catch (e) {
      return false
    }
}

what result do you expect? What is the error message actually seen?

Please give your advice, thank you ~

Jan.08,2022

you have asked for data, so there is no need to use actions, right? just commit it?

store.commit('adduser',user)

Asynchronous can use actions, in store, but ultimately modify the data using mutations's interface. It is recommended that you first refer to the official website to write demo

.
Menu