Skip to content

Commit d6f332c

Browse files
committed
Docs: new vue-plugin docs
1 parent 654a0f5 commit d6f332c

File tree

1 file changed

+39
-12
lines changed

1 file changed

+39
-12
lines changed

docs/vue-plugin.md

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,43 @@
22
title: Vue Plugin
33
---
44

5-
This `feathers-vuex` release includes a Vue plugin which gives all of your components easy access to the exciting new Models feature. It also automatically registers the `feathers-vuex-data` component. You can pass `components: false` in the options to not globally register the component. Here's how to use the plugin:
5+
# The Vue Plugin
6+
7+
This `feathers-vuex` release includes a Vue plugin which gives all of your components easy access to the data modeling classes. It also automatically registers the included components. The below example is based on the [setup instructions in the API overview](/api-overview.html#setup).
68

79
```js
10+
// src/store/store.js
811
import Vue from 'vue'
912
import Vuex from 'vuex'
10-
import feathersVuex from 'feathers-vuex'
11-
import feathersClient from './feathers-client'
12-
13-
// Get a reference to the FeathersVuex plugin
14-
const { service, auth, FeathersVuex } = feathersVuex(feathersClient, { idField: '_id' })
13+
import { FeathersVuex } from '../feathers-client'
14+
import auth from './store.auth'
1515

16-
// Register the plugin with Vue.
17-
Vue.use(FeathersVuex)
1816
Vue.use(Vuex)
17+
Vue.use(FeathersVuex)
18+
19+
const requireModule = require.context(
20+
// The path where the service modules live
21+
'./services',
22+
// Whether to look in subfolders
23+
false,
24+
// Only include .js files (prevents duplicate imports`)
25+
/.js$/
26+
)
27+
const servicePlugins = requireModule
28+
.keys()
29+
.map(modulePath => requireModule(modulePath).default)
1930

2031
export default new Vuex.Store({
21-
plugins: [
22-
service('todos')
23-
]
32+
state: {},
33+
mutations: {},
34+
actions: {},
35+
plugins: [...servicePlugins, auth]
2436
})
2537
```
2638

27-
Now, in your components, you'll have access to the `this.$FeathersVuex` object, which contains references to the Model classes, keyed by name. The name of the model class is automatically inflected to singular, initial caps, based on the last section of the service path (split by `/`). Here are some examples of what this looks like:
39+
## Using the Vue Plugin
40+
41+
Once registered, you'll have access to the `this.$FeathersVuex` object, which contains references to the Model classes, keyed by name. The name of the model class is automatically inflected to singular, initial caps, based on the last section of the service path (split by `/`). Here are some examples of what this looks like:
2842

2943
| Service Name | Model Name in `$FeathersVuex` |
3044
| ------------------------- | ----------------------------- |
@@ -42,3 +56,16 @@ created () {
4256
// `todo` is now a model instance
4357
}
4458
```
59+
60+
## Included Components
61+
62+
When you register the Vue Plugin, a few components are automatically globally registered:
63+
64+
- The [Renderless Data components](/data-components.html)
65+
- The [`FeathersVuexFormWrapper` component](/feathers-vuex-form-wrapper.html)
66+
67+
You can pass `components: false` in the options to not globally register the component:
68+
69+
```js
70+
Vue.use(FeathersVuex, { components: false })
71+
```

0 commit comments

Comments
 (0)