You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/guide/usage.md
+8-1Lines changed: 8 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -94,12 +94,19 @@ Vuex ORM Axios will automatically save this data to the store, and the users ent
94
94
95
95
Under the hood, the plugin will persist data to the store by determining which records require inserting and which require updating. To accomplish this, the plugin passes data to the Vuex ORM `insertOrUpdate` model method. Therefore, only valid model attributes will be persisted to the store.
96
96
97
+
As of 0.9.3+ you may configure Vuex ORM Axios to persist data using an alternative Vuex ORM persist method other than the default `insertOrUpdate`. For example, you can refresh entities by passing the `persistBy` option as `'create'` which will persist data using the model's `create` method:
98
+
99
+
```js
100
+
User.api().get('url', { persistBy:'create' })
101
+
```
102
+
97
103
If you do not want to persist response data automatically, you can defer persistence by configuring the request with the `{ save: false }` option.
98
104
99
105
**See also**:
100
106
101
107
-[Deferring Persistence](#deferring-persistence)
102
-
-[Vuex ORM - Insert or Update](https://vuex-orm.org/guide/data/inserting-and-updating.html#insert-or-update)
@@ -45,19 +45,50 @@ export default class Response {
45
45
46
46
if(!this.validateData(data)){
47
47
console.warn(
48
-
'[Vuex ORM Axios] The response data could not be saved to the store because it is not an object or an array. You might want to use `dataTransformer` option to handle non-array/object response before saving it to the store.'
48
+
'[Vuex ORM Axios] The response data could not be saved to the store '+
49
+
'because it is not an object or an array. You might want to use '+
50
+
'`dataTransformer` option to handle non-array/object response '+
51
+
'before saving it to the store.'
49
52
)
50
53
51
54
return
52
55
}
53
56
54
-
this.entities=awaitthis.model.insertOrUpdate({ data })
57
+
letmethod=this.config.persistByasPersistMethods
58
+
59
+
if(!this.validatePersistMethod(method)){
60
+
console.warn(
61
+
'[Vuex ORM Axios] The "persistBy" option configured is not a '+
62
+
'recognized value. Response data will be persisted by the '+
63
+
'default `insertOrUpdate` method.'
64
+
)
65
+
66
+
method='insertOrUpdate'
67
+
}
68
+
69
+
this.entities=awaitthis.persist(method,{ data })
55
70
56
71
this.isSaved=true
57
72
}
58
73
59
74
/**
60
-
* Delete store record depending on `delete` option.
75
+
* Determine the method to be used to persist the payload to the store.
0 commit comments