File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import Axios from '../orm/axios' ;
12import Action from './Action'
23import Context from '../common/context'
34
45export 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}
You can’t perform that action at this time.
0 commit comments