Skip to content

Commit 6fa9de9

Browse files
authored
Nuxt modules modes (#99)
1 parent 4b288b9 commit 6fa9de9

File tree

1 file changed

+44
-17
lines changed

1 file changed

+44
-17
lines changed

docs/guide/nuxt.md

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,61 @@
22

33
[[toc]]
44

5-
Since Version 1.0.0.RC.21 there is support for SSR. You will need
6-
[node-fetch](https://www.npmjs.com/package/node-fetch) in order to make it work and you have to
7-
construct your own HttpLink instance.
5+
Since Version 1.0.0.RC.21 there is support for SSR. The following example shows how to setup
6+
Vuex-ORM and Plugin GraphQL with Nuxt.
87

9-
Example store setup for nuxt.js:
8+
`/store/index.js`:
109

11-
```javascript{13,14,15}
12-
import Vuex from 'vuex';
10+
```javascript
11+
import installVuexOrm from '~/plugins/vuex-orm';
12+
import '~/plugins/graphql';
13+
14+
export default { plugins: [installVuexOrm] };
15+
```
16+
17+
18+
`/plugins/vuex-orm.js`:
19+
20+
```javascript
21+
import VuexORM from '@vuex-orm/core';
22+
import database from '~/data/database';
23+
24+
export default (store) => {
25+
VuexORM.install(database)(store);
26+
};
27+
28+
```
29+
30+
`/data/database.js`:
31+
32+
```javascript
33+
import { Database } from '@vuex-orm/core';
34+
import User from '~/data/models/user';
35+
// ...
36+
37+
const database = new Database();
38+
database.register(User);
39+
// ...
40+
41+
export default database;
42+
43+
```
44+
45+
46+
`/plugins/graphql.js`:
47+
48+
```javascript
1349
import VuexORM from '@vuex-orm/core';
1450
import VuexORMGraphQL from '@vuex-orm/plugin-graphql';
1551
import { HttpLink } from 'apollo-link-http';
16-
import database from './database';
1752
import fetch from 'node-fetch';
53+
import database from '~/data/database';
1854

19-
const options = {
20-
database,
21-
url: process.env.BACKEND_URL + '/api/v2',
22-
};
55+
const options = { database, url: '...' };
2356

2457
if (process.server) {
2558
options.link = new HttpLink({ uri: options.url, fetch });
2659
}
2760

2861
VuexORM.use(VuexORMGraphQL, options);
29-
30-
31-
export default function createStore () {
32-
const plugins = [VuexORM.install(database)];
33-
return new Vuex.Store({ plugins });
34-
}
3562
```

0 commit comments

Comments
 (0)