我必须在操作中使用状态数据,但不确定如何实现。
const state = {
oOptions: {}
};
我应该从组件中获取oOptions
,然后传递给操作吗?
// Access State Data from Component then Pass to Action
computed: mapGetters(['oOptions']),
methods: {
fetchProducts: function() {
this.$store.dispatch('fetchProducts', this.oOptions).then(/*doSomething*/);
}
}
const actions = {
async fetchProducts({ commit }, oOptions) {
oOptions
// commit()
}
}
还是只是从操作中访问oOptions
?
// Accessing State Data in Action
const actions = {
async fetchProducts({ state, commit }) {
state.oOptions
// commit()
}
}