when I use axios in many modules
// each module has to import
import axios from 'axios'
export default {
...
actions: {
getUsers ({ commit }) {
axios.get('/users').then(data => {
commit('users', data)
})
}
}
}
If the actions first param context is configurable, it could be like this,
the axios may be db, model or socket
// in store/index
import axios from 'axios'
const store = new Vuex.Store({
context: {
axios
},
...
modules: {
...
}
})
// in module/user
export default {
...,
actions: {
getUsers ({ axios, commit }) {
axios.get('/users').then(data => {
commit('users', data)
})
}
}
}
I read src/store.js and find that the context is not configurable.
There was this kind of discussion in the past and we didn't introduce the feature that can be inject something in the action context. See #571
You can use the action enhancer approach to do that.
I read #571, thank you
Most helpful comment
There was this kind of discussion in the past and we didn't introduce the feature that can be inject something in the action context. See #571
You can use the action enhancer approach to do that.