Answer the question
In order to leave comments, you need to log in
How to get vuex asynchronous state?
import Axios from 'axios'
const state = {
profile: null
}
const actions = {
loadProfileOnce: async ({commit}, id) => {
try {
const {data} = await Axios.get('http://127.0.0.1:3001/api/profile/' + id)
console.log(data)
if (data) {
commit('loadProfileOnce', data)
} else {
console.log('errorororo')
}
} catch (error) {
throw error
}
}
}
const mutations = {
loadProfileOnce: (state, payload) => {
state.profile = payload
}
}
const getters = {
getOneProfile: state => {
return state.profile
}
}
created () {
this.$store.dispatch('loadProfileOnce', this.profileId)
},
computed: {
...mapGetters(['getOneProfile'])
},
Answer the question
In order to leave comments, you need to log in
getOneProfile: state => {
return state.profile
}
<КакойТоКомпонент v-if="данные" />
<ИндикаторЗагрузки v-else />
{{ getOneProfile.profile.name }}
getOneProfile already returns profile, maybe this is the problem?
try {{ getOneProfile.name }}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question