Use with Vuex
John0x opened this issue · 5 comments
Hey, is there any chance that this can be used with Vuex?
I would like to have my rest client as a factory/service and then use that within my store actions.
Surely yes, Here's the counter example: https://jsfiddle.net/ye_well/dcmxfcz3/
if you are using vue-resource as the rest client, you can access the global http/resource with this.$Vue.http or this.$Vue.resource in the factory class
@ye-will thanks for example, but is this possible without wrapping the store in a service?
I want to use a service from within an action of my store.
@John0x there isn't a way to use vue-factory in a Vuex instance directly up to now. To use a service from within an action, you need to dispatch actions with services as payload.
export default {
// ...
providers: ['service'],
methods: {
action: function() {
this.$store.dispatch('action', {
// ...
service: this.service
})
}
}
}
Looks very DIRTY, but that's the only solution.