File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -23,9 +23,7 @@ export default class Fetch extends Action {
2323 data,
2424 } ) ;
2525 } )
26- . catch ( error => {
27- commit ( 'onError' , error )
28- } )
26+ . catch ( error => commit ( 'onError' , error ) )
2927
3028 return request ;
3129 }
Original file line number Diff line number Diff line change 1+ import Axios from '../orm/axios' ;
12import Action from './Action'
3+ import Context from '../common/context'
24
35export default class Get extends Action {
4- static call ( { state, dispatch } , params = { } ) {
5- console . log ( state , dispatch , params ) ;
6+ /**
7+ * Call $get method
8+ * @param {object } store
9+ * @param {object } params
10+ */
11+ static async call ( { state, commit } , params = { } ) {
12+ const context = Context . getInstance ( ) ;
13+ const model = context . getModelFromState ( state ) ;
14+ const endpoint = Action . transformParams ( '$get' , 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 => commit ( 'onError' , error ) )
27+
28+ return request ;
629 }
730}
Original file line number Diff line number Diff line change @@ -47,23 +47,23 @@ export default class VuexOrmAxios {
4747 return entity ;
4848 } ) ;
4949
50- context . components . Model . $fetch = async function ( config = { } ) {
50+ context . components . Model . $fetch = function ( config = { } ) {
5151 return this . dispatch ( '$fetch' , config ) ;
5252 } ;
5353
54- context . components . Model . $get = async function ( config = { } ) {
54+ context . components . Model . $get = function ( config = { } ) {
5555 return this . dispatch ( '$get' , config ) ;
5656 } ;
5757
58- context . components . Model . $create = async function ( config = { } ) {
58+ context . components . Model . $create = function ( config = { } ) {
5959 return this . dispatch ( '$create' , config ) ;
6060 } ;
6161
62- context . components . Model . $update = async function ( config = { } ) {
62+ context . components . Model . $update = function ( config = { } ) {
6363 return this . dispatch ( '$update' , config ) ;
6464 } ;
6565
66- context . components . Model . $delete = async function ( config = { } ) {
66+ context . components . Model . $delete = function ( config = { } ) {
6767 return this . dispatch ( '$delete' , config ) ;
6868 } ;
6969 }
You can’t perform that action at this time.
0 commit comments