ApiService()
API 呼び出しを抽象化している があります。サービス内からアプリ レベルの変更をdispatch('SET_BUSY')
行いたいの
ですが、次のエラーが発生します。dispatch('SET_NOT_BUSY')
TypeError: dispatch is not a function. (In 'dispatch('SET_BUSY')', 'dispatch' is undefined)
/vuex/actions.js
import { ApiService } from './services';
export const setAppMode = function ({ dispatch }) {
ApiService({
noun: 'Application',
verb: 'GetMode'
}, response => {
dispatch('SET_APP_MODE', response.Data.mode);
},
dispatch);
};
/vuex/services.js
import Vue from 'vue';
export const ApiService = (options = {}, callback, dispatch) => {
let endpoint = 'localhost/api/index.php';
let parameters = options.data;
dispatch('SET_BUSY');
Vue.http.post(endpoint, parameters, []).then((promise) => {
return promise.text();
}, (promise) => {
return promise.text();
}).then(response => {
response = JSON.parse(response);
dispatch('SET_NOT_BUSY');
if (response.Result === 'ERROR') {
console.log('ERROR: ' + response.Error.Message);
}
callback(response);
});
};