You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|[options.watch]|`Boolean`| default `false`, watch the '*.vue' file changes |
158
160
|[options.plugins]|`Array`\|`string`| vue plugins, e.g. `[vueRouter]` or `[{plugin: vueRouter,options: {}}]`, it also support using plugin path string, e.g. `[path.resolve('../app/resource.js')]`|
159
161
|[options.preCompile]|`Array`| pre-compile `*.vue` file list |
160
162
|[options.head]|`Object`| common html head config see detail in [Component Head](#component-head)|
@@ -228,6 +230,39 @@ Then the result
228
230
</html>
229
231
```
230
232
233
+
## vuex or vue-router
234
+
235
+
When using vuex or vue-router in server-side rendering, we need to create a vuex or vue-router instance for each request, so when you inject a vuex or vue-router instance into a component, you need to add a factory function to the instance , The function will return an instance when called, the default method is named `$ ssrInstance`, such as:
236
+
237
+
**vuex**
238
+
239
+
```js
240
+
constoptions= {
241
+
state: {
242
+
hello:'world!'
243
+
}
244
+
};
245
+
246
+
conststore=newVuex(options);
247
+
store.$ssrInstance= () =>newVuex(options);
248
+
exportdefaultstore;
249
+
```
250
+
251
+
**vue-router**
252
+
253
+
```js
254
+
constoptions= {
255
+
mode:'history',
256
+
routes: [
257
+
{ path:'/user/:id', component: User }
258
+
]
259
+
})
260
+
261
+
constrouter=newVueRouter(options)
262
+
router.$ssrInstance= () =>newVuex(options);
263
+
exportdefaultrouter;
264
+
```
265
+
If you use `vue-router` in server rendering, you need to set `mode` to `history`
0 commit comments