Skip to content

Commit c422b58

Browse files
committed
docs: move to v-slot in renderless components
1 parent dcbcc24 commit c422b58

File tree

1 file changed

+34
-31
lines changed

1 file changed

+34
-31
lines changed

docs/data-components.md

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ Here's what it looks like to use the new component:
1212

1313
```html
1414
<template>
15-
<FeathersVuexFind service="categories" :query="{}" watch="query">
16-
<section class="admin-categories" slot-scope="{ items: categories }">
15+
<FeathersVuexFind v-slot="{ items: categories }" service="categories" :query="{}" watch="query">
16+
<section class="admin-categories">
1717
{{categories}}
1818
</section>
1919
</FeathersVuexFind>
@@ -67,8 +67,8 @@ export default {
6767
The `FeathersVuexFind` component retrieves data from the API server, puts it in the Vuex store, then transparently retrieves the live, reactive data from the store and displays it to the user.
6868

6969
```vue
70-
<FeathersVuexFind service="users" :query="{}" watch="query">
71-
<section slot-scope="{ items: users }">
70+
<FeathersVuexFind v-slot="{ items: users }" service="users" :query="{}" watch="query">
71+
<section>
7272
{{users}}
7373
</section>
7474
</FeathersVuexFind>
@@ -85,10 +85,8 @@ The `FeathersVuexGet` component allows fetching data from directly inside a temp
8585

8686
```html
8787
<template>
88-
<FeathersVuexGet service="users" :id="id" :params="params" :watch="[id, params]">
89-
<template slot-scope="{ item: user }">
88+
<FeathersVuexGet v-slot="{ item: user }" service="users" :id="id" :params="params" :watch="[id, params]">
9089
{{ user }}
91-
</template>
9290
</FeathersVuexGet>
9391
</template>
9492

@@ -163,8 +161,8 @@ The `<FeathersVuexGet>` component has these unique props.
163161
When using these components, the scope data will become available to the first element nested inside the `FeathersVuexFind` or `FeathersVuexGet` tags. It's accessible using the `scope-data="props"` attribute:
164162

165163
```html
166-
<FeathersVuexFind service="categories" :query="{}">
167-
<div slot-scope="props">
164+
<FeathersVuexFind v-slot="props" service="categories" :query="{}">
165+
<div>
168166
{{props.items}}
169167
</div>
170168
</FeathersVuexFind>
@@ -187,11 +185,11 @@ It's also possible to modify the scope data by passing a function as the `edit-s
187185

188186
### Destructuring props
189187

190-
Use the object destructuring syntax to pull specific variables out of the `slot-scope` object. In the following example, instead of using `slot-scope="props"`, it directly accesses the `items` prop through destructuring:
188+
Use the object destructuring syntax to pull specific variables out of the `slot-scope` object. In the following example, instead of using `v-slot="props"`, it directly accesses the `items` prop through destructuring:
191189

192190
```html
193-
<FeathersVuexFind service="categories" :query="{}">
194-
<div slot-scope="{ items }">
191+
<FeathersVuexFind v-slot="{ items }" service="categories" :query="{}">
192+
<div>
195193
{{items}}
196194
</div>
197195
</FeathersVuexFind>
@@ -202,8 +200,8 @@ Use the object destructuring syntax to pull specific variables out of the `slot-
202200
You can also rename scope props through the Object destructuring syntax. The `slot-scope` in the next example shows how to give the items a more-descriptive name:
203201

204202
```html
205-
<FeathersVuexFind service="categories" :query="{}">
206-
<div slot-scope="{ items: categories }">
203+
<FeathersVuexFind v-slot="{ items: categories } service="categories" :query="{}">
204+
<div>
207205
{{categories}}
208206
</div>
209207
</FeathersVuexFind>
@@ -216,8 +214,8 @@ You can also rename scope props through the Object destructuring syntax. The `
216214
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.
217215
218216
```html
219-
<FeathersVuexFind service="todos">
220-
<div slot-scope="props">
217+
<FeathersVuexFind v-slot="props" service="todos">
218+
<div>
221219
{{props.items}}
222220
</div>
223221
</FeathersVuexFind>
@@ -228,8 +226,8 @@ In this example, only the `service` attribute is provided. There is no `query` n
228226
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.
229227
230228
```html
231-
<FeathersVuexFind service="todos" :query="{}">
232-
<div slot-scope="props">
229+
<FeathersVuexFind v-slot="props" service="todos" :query="{}">
230+
<div>
233231
{{props.items}}
234232
</div>
235233
</FeathersVuexFind>
@@ -240,8 +238,8 @@ This example fetches data from the API server because a query was provided. Int
240238
If you've already pulled a bunch of data from the server, you can use the `local` prop to only query the local data:
241239
242240
```html
243-
<FeathersVuexFind service="todos" :query="{}" local>
244-
<div slot-scope="props">
241+
<FeathersVuexFind v-slot="props" service="todos" :query="{}" local>
242+
<div>
245243
{{props.items}}
246244
</div>
247245
</FeathersVuexFind>
@@ -253,11 +251,12 @@ Sometimes you want to query new data from the server whenever the query changes.
253251
254252
```html
255253
<FeathersVuexFind
254+
v-slot="props"
256255
service="todos"
257256
:query="{ isComplete: true }"
258257
watch="query"
259258
>
260-
<div slot-scope="props">
259+
<div>
261260
{{props.items}}
262261
</div>
263262
</FeathersVuexFind>
@@ -267,11 +266,12 @@ This next example watches a single prop from the query:
267266
268267
```html
269268
<FeathersVuexFind
269+
v-slot="props"
270270
service="todos"
271271
:query="{ isComplete: true, dueDate: 'today' }"
272272
watch="query.dueDate"
273273
>
274-
<div slot-scope="props">
274+
<div>
275275
{{props.items}}
276276
</div>
277277
</FeathersVuexFind>
@@ -281,11 +281,12 @@ You can also provide an array of strings to watch multiple properties:
281281
282282
```html
283283
<FeathersVuexFind
284+
v-slot="props"
284285
service="dogs"
285286
:query="{ breed: 'mixed', bites: true, hasWorms: false }"
286287
:watch="['query.breed', 'query.bites']"
287288
>
288-
<div slot-scope="props">
289+
<div>
289290
{{props.items}}
290291
</div>
291292
</FeathersVuexFind>
@@ -298,12 +299,13 @@ In this scenario, the `fetchQuery` is be used to grab a larger dataset from the
298299
```html
299300
<template>
300301
<FeathersVuexFind
302+
v-slot="{ items: todos }"
301303
service="todos"
302304
:query="{ isComplete }"
303305
:fetchQuery="{ userId }"
304306
watch="query.userId"
305307
>
306-
<div slot-scope="{ items: todos }">
308+
<div>
307309
{{todos}}
308310
</div>
309311
</FeathersVuexFind>
@@ -326,11 +328,12 @@ The `edit-scope` function allows you to modify the scope before passing it down
326328
```html
327329
<template>
328330
<FeathersVuexFind
331+
v-slot="{ parentCategories, categoriesByParent }"
329332
service="categories"
330333
:query="{}"
331334
:edit-scope="prepareCategories"
332335
>
333-
<ul slot-scope="{ parentCategories, categoriesByParent }">
336+
<ul>
334337
<li v-for="parent in parentCategories" :key="parent._id">
335338
<p>{{parent.name}}</p>
336339
<ul>
@@ -367,12 +370,13 @@ When you want to use server-side pagination you need to pass the ids from the se
367370
```html
368371
<template>
369372
<FeathersVuexFind
373+
v-slot="{ items: todos }"
370374
:service="service"
371375
:query="internalQuery"
372376
:fetch-query="fetchQuery"
373377
:edit-scope="getPaginationInfo"
374378
>
375-
<div slot-scope="{ items: todos }">
379+
<div>
376380
{{todos}}
377381
</div>
378382
</FeathersVuexFind>
@@ -429,15 +433,13 @@ Sometimes you only want to query the API server when certain conditions are met.
429433
<input type="text" v-model="userSearch"/>
430434
431435
<FeathersVuexFind
436+
v-slot="{ items: users, isFindPending: areUsersLoading }"
432437
service="users"
433438
:query="usersQuery"
434439
watch="query"
435440
:queryWhen="userSearch.length > 2"
436441
>
437-
<ul
438-
slot-scope="{ items: users, isFindPending: areUsersLoading }"
439-
:class="[ areUsersLoading && 'is-loading' ]"
440-
>
442+
<ul :class="[ areUsersLoading && 'is-loading' ]">
441443
<li v-for="user in users" :key="user._id">
442444
{{user.email}}
443445
</li>
@@ -469,10 +471,11 @@ You can perform `get` requests with the `FeathersVuexGet` component and its `id`
469471

470472
```html
471473
<FeathersVuexGet
474+
v-slot="{ item: currentUser, isGetPending }"
472475
service="todos"
473476
:id="selectedUserId"
474477
>
475-
<div slot-scope="{ item: currentUser, isGetPending }">
478+
<div>
476479
<div v-if="isGetPending" class="loading"> loading... </div>
477480
{{currentUser}}
478481
</div>

0 commit comments

Comments
 (0)