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/data-components.md
+40-22Lines changed: 40 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,15 +5,20 @@ sidebarDepth: 3
5
5
6
6
# Renderless Data Components
7
7
8
-
There are two new renderless data provider components: `<FeathersVuexFind>`and `<FeathersVuexGet>`. They simplify performing queries against the store and/or the API server. They make the data available inside each component's default slot.
8
+
There are three renderless data provider components: `<FeathersVuexFind>`, `<FeathersVuexGet>`and `<FeathersVuexCount>`. They simplify performing queries against the store and/or the API server. They make the data available inside each component's default slot.
9
9
10
10
To see why you might want to use these components, below are two example components that are functionally equivalent.
11
11
12
12
Here's what it looks like to use the new component:
When using these components, the scope data will become available to the `FeathersVuexFind` or `FeathersVuexGet` tags. It's accessible using the `v-slot="props"` attribute:
224
+
When using these components, the scope data will become available to the `FeathersVuexFind`, `FeathersVuexGet` and `FeathersVuexCount` tags. It's accessible using the `v-slot="props"` attribute:
@@ -215,8 +231,6 @@ When using these components, the scope data will become available to the `Feathe
215
231
</FeathersVuexFind>
216
232
```
217
233
218
-
By default, the following props are available in the scope data:
219
-
220
234
It's also possible to modify the scope data by passing a function as the `edit-scope` prop. See the example for [modifying scope data](#Modify-the-scope-data)
221
235
222
236
### Destructuring props
@@ -236,7 +250,11 @@ Use the object destructuring syntax to pull specific variables out of the `v-slo
236
250
You can also rename scope props through the Object destructuring syntax. The `v-slot` in the next example shows how to give the items a more-descriptive name:
@@ -245,7 +263,7 @@ You can also rename scope props through the Object destructuring syntax. The `
245
263
246
264
## Usage Examples
247
265
248
-
### A basic find all
266
+
####A basic find all
249
267
250
268
In this example, only the `service` attribute is provided. There is no `query` nor `id` provided, so no queries are made. So `props.items` in this example returns an empty array.
251
269
@@ -257,9 +275,9 @@ In this example, only the `service` attribute is provided. There is no `query` n
257
275
</FeathersVuexFind>
258
276
```
259
277
260
-
### Fetch data from the API and the same data from the Vuex store
278
+
####Fetch data from the API and the same data from the Vuex store
261
279
262
-
This example fetches data from the API server because a query was provided. Internally, this same `query` is used for both the `find` action and the `find` getter. Read other examples to see how to use distinct queries. Be aware that if you use pagination directives like `$skip` or `$limit`, you must use two queries to get the records you desire.
280
+
This example fetches data from the API server because a query was provided. Internally, this same `query` is used for both the `find` action and the `find` getter. Read other examples to see how to use distinct queries. Be aware that if you use pagination directives like `$skip` or `$limit`, you must use two queries to get the records you desire.
@@ -269,7 +287,7 @@ This example fetches data from the API server because a query was provided. Int
269
287
</FeathersVuexFind>
270
288
```
271
289
272
-
### Only get data from the local Vuex store
290
+
####Only get data from the local Vuex store
273
291
274
292
If you've already pulled a bunch of data from the server, you can use the `local` prop to only query the local data:
275
293
@@ -281,7 +299,7 @@ If you've already pulled a bunch of data from the server, you can use the `local
281
299
</FeathersVuexFind>
282
300
```
283
301
284
-
### Watch the query and re-fetch from the API
302
+
####Watch the query and re-fetch from the API
285
303
286
304
Sometimes you want to query new data from the server whenever the query changes. Pass an array of attribute names to the `watch` attribute re-query whenever upon change. This example watches the entire query object:
287
305
@@ -328,7 +346,7 @@ You can also provide an array of strings to watch multiple properties:
328
346
</FeathersVuexFind>
329
347
```
330
348
331
-
### Use a distinct `params` and `fetchParams`
349
+
####Use a distinct `params` and `fetchParams`
332
350
333
351
In this scenario, the `fetchParams` is be used to grab a larger dataset from the API server (all todos with a matching `userId`). The `params` is used by the `find` getter to display a subset of this data from the store. If the `isComplete` attribute gets set to `true`, only completed todos will be displayed. Since a `fetchParams` is provided, the `watch` strings will be modified internally to watch the `fetchParams` object. This means if you are watching `params.query.userId` and you add a `fetchParams`, the component is smart enough to know you meant `fetchParams.query.userId`. You don't have to rewrite your `watch` attribute after adding a `fetchParams` prop.
334
352
@@ -357,7 +375,7 @@ export default {
357
375
</script>
358
376
```
359
377
360
-
### Modify the scope data
378
+
####Modify the scope data
361
379
362
380
The `edit-scope` function allows you to modify the scope before passing it down to the default slot. This feature can be super useful for preparing the data for the template. The `prepareCategories` method in this next example adds two properties to the scope data, which are used to create a nested category structure:
363
381
@@ -399,7 +417,7 @@ export default {
399
417
</script>
400
418
```
401
419
402
-
### server-side pagination
420
+
####server-side pagination
403
421
404
422
When you want to use server-side pagination you need to pass the ids from the server to vuex. It can be done by a combination of `params`, `fetchParams` and `editScope` as described below. The `fetchParams`-prop is only computed after items from the server arrived. The ids for the `find` getter as well as the total amount of available values `total` are extracted by the `edit-scope` function and stored in `data`:
405
423
@@ -465,7 +483,7 @@ export default {
465
483
</script>
466
484
```
467
485
468
-
### Query when certain conditions are met
486
+
####Query when certain conditions are met
469
487
470
488
Sometimes you only want to query the API server when certain conditions are met. This example shows how to query the API server when the `userSearch` has as least three characters. This property does not affect the internal `find` getter, so the `items` will still update when the `userSearch` property has fewer than three characters, just no API request will be made. The `isFindPending` attribute is used to indicate when data is being loaded from the server.
471
489
@@ -509,7 +527,7 @@ export default {
509
527
</script>
510
528
```
511
529
512
-
### Use a get request
530
+
####Use a get request
513
531
514
532
You can perform `get` requests with the `FeathersVuexGet` component and its `id` property. In the next example, when the `selectedUserId` changes, a get request will automatically fetch and display the matching user record. It also shows how to use the `isGetPending` prop to update the UI
0 commit comments