Skip to content

Commit 76cd165

Browse files
committed
Added Fetch Method
1 parent 8e567c7 commit 76cd165

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

src/actions/Fetch.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,32 @@
1+
import Axios from '../orm/axios';
12
import Action from './Action'
23
import Context from '../common/context'
34

45
export default class Fetch extends Action {
5-
static async call ({ state }, params = {}) {
6+
/**
7+
* Call $fetch method
8+
* @param {object} store
9+
* @param {object} params
10+
*/
11+
static async call ({ state, commit }, params = {}) {
612
const context = Context.getInstance();
713
const model = context.getModelFromState(state);
814
const endpoint = Action.transformParams('$fetch', model, params);
15+
const axios = new Axios(model.methodConf.http);
16+
const request = axios.get(endpoint);
17+
18+
commit('onRequest');
19+
request
20+
.then(data => {
21+
commit('onSuccess')
22+
model.insertOrUpdate({
23+
data,
24+
});
25+
})
26+
.catch(error => {
27+
commit('onError', error)
28+
})
29+
30+
return request;
931
}
1032
}

0 commit comments

Comments
 (0)