Skip to content

Commit dfd30aa

Browse files
committed
docs: Update vue readme with MockPlugin
1 parent e11de65 commit dfd30aa

File tree

1 file changed

+38
-34
lines changed

1 file changed

+38
-34
lines changed

packages/vue/README.md

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -206,47 +206,51 @@ class TickerStream implements Manager {
206206

207207
### [Integrated data mocking](https://dataclient.io/docs/api/Fixtures)
208208

209-
```vue
210-
<template>
211-
<MockResolver :fixtures="fixtures">
212-
<ArticleList :maxResults="10" />
213-
</MockResolver>
214-
</template>
215-
216-
<script setup lang="ts">
217-
// Planned API - not yet implemented
218-
const fixtures = [
219-
{
220-
endpoint: ArticleResource.getList,
221-
args: [{ maxResults: 10 }] as const,
222-
response: [
209+
```typescript
210+
import { createApp } from 'vue';
211+
import { DataClientPlugin } from '@data-client/vue';
212+
import { MockPlugin } from '@data-client/vue/test';
213+
214+
const app = createApp(App);
215+
app.use(DataClientPlugin);
216+
if (process.env.NODE_ENV !== 'production') {
217+
app.use(MockPlugin, {
218+
fixtures: [
223219
{
224-
id: '5',
225-
title: 'first post',
226-
body: 'have a merry christmas',
227-
author: { id: '10', username: 'bob' },
228-
createdAt: new Date(0).toISOString(),
220+
endpoint: ArticleResource.getList,
221+
args: [{ maxResults: 10 }] as const,
222+
response: [
223+
{
224+
id: '5',
225+
title: 'first post',
226+
body: 'have a merry christmas',
227+
author: { id: '10', username: 'bob' },
228+
createdAt: new Date(0).toISOString(),
229+
},
230+
{
231+
id: '532',
232+
title: 'second post',
233+
body: 'never again',
234+
author: { id: '10', username: 'bob' },
235+
createdAt: new Date(0).toISOString(),
236+
},
237+
],
229238
},
230239
{
231-
id: '532',
232-
title: 'second post',
233-
body: 'never again',
234-
author: { id: '10', username: 'bob' },
235-
createdAt: new Date(0).toISOString(),
240+
endpoint: ArticleResource.update,
241+
response: ({ id }, body) => ({
242+
...body,
243+
id,
244+
}),
236245
},
237246
],
238-
},
239-
{
240-
endpoint: ArticleResource.update,
241-
response: ({ id }, body) => ({
242-
...body,
243-
id,
244-
}),
245-
},
246-
];
247-
</script>
247+
});
248+
}
249+
app.mount('#app');
248250
```
249251

252+
**Note:** `MockPlugin` must be installed after `DataClientPlugin` and before mounting the app.
253+
250254
### ...all typed ...fast ...and consistent
251255

252256
For the small price of 9kb gziped. &nbsp;&nbsp; [🏁Get started now](https://dataclient.io/docs/getting-started/installation)

0 commit comments

Comments
 (0)