|
2 | 2 |
|
3 | 3 | [[toc]]
|
4 | 4 |
|
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. |
8 | 7 |
|
9 |
| -Example store setup for nuxt.js: |
| 8 | +`/store/index.js`: |
10 | 9 |
|
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 |
13 | 49 | import VuexORM from '@vuex-orm/core';
|
14 | 50 | import VuexORMGraphQL from '@vuex-orm/plugin-graphql';
|
15 | 51 | import { HttpLink } from 'apollo-link-http';
|
16 |
| -import database from './database'; |
17 | 52 | import fetch from 'node-fetch';
|
| 53 | +import database from '~/data/database'; |
18 | 54 |
|
19 |
| -const options = { |
20 |
| - database, |
21 |
| - url: process.env.BACKEND_URL + '/api/v2', |
22 |
| -}; |
| 55 | +const options = { database, url: '...' }; |
23 | 56 |
|
24 | 57 | if (process.server) {
|
25 | 58 | options.link = new HttpLink({ uri: options.url, fetch });
|
26 | 59 | }
|
27 | 60 |
|
28 | 61 | VuexORM.use(VuexORMGraphQL, options);
|
29 |
| -
|
30 |
| -
|
31 |
| -export default function createStore () { |
32 |
| - const plugins = [VuexORM.install(database)]; |
33 |
| - return new Vuex.Store({ plugins }); |
34 |
| -} |
35 | 62 | ```
|
0 commit comments