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
Render the bundle to a string. The context object is optional. The callback is a typical Node.js style callback where the first argument is the error and the second argument is the rendered string.
Provide a template for the entire page's HTML. The template should contain a comment `<!--vue-ssr-outlet-->` which serves as the placeholder for rendered app content.
54
54
55
-
The template also supports basic interpolation using the render context:
55
+
模板还支持使用渲染上下文(render context)进行基本插值:
56
56
57
-
-Use double-mustache for HTML-escaped interpolation;
58
-
-Use triple-mustache for non-HTML-escaped interpolation.
57
+
-使用双花括号(double-mustache)进行 HTML 转义插值(HTML-escaped interpolation);
58
+
-使用三花括号(triple-mustache)进行 HTML 不转义插值(non-HTML-escaped interpolation)。
59
59
60
-
The template automatically injects appropriate content when certain data is found on the render context:
60
+
当在渲染上下文(render context)找到某些数据时,模板会自动注入合适的内容:
61
61
62
-
-`context.head`: (string) any head markup that should be injected into the head of the page.
63
-
-`context.styles`: (string) any inline CSS that should be injected into the head of the page. Note this property will be automatically populated if using `vue-loader` + `vue-style-loader` for component CSS.
64
-
-`context.state`: (Object) initial Vuex store state that should be inlined in the page as `window.__INITIAL_STATE__`. The inlined JSON is automatically sanitized with [serialize-javascript](https://github.com/yahoo/serialize-javascript)to prevent XSS.
Provide a client build manifest object generated by `vue-server-renderer/client-plugin`. The client manifest provides the bundle renderer with the proper information for automatic asset injection into the HTML template. For more details, see [Generating clientManifest](./build-config.md#generating-clientmanifest).
For other types of assets such as images or fonts, preloading too much may waste bandwidth and even hurt performance, so what to preload will be scenario-dependent. You can control precisely what to preload using the `shouldPreload`option:
@@ -125,35 +125,35 @@ See [Introducing the Server Bundle](./bundle-renderer.md) and [Build Configurati
125
125
#### `runInNewContext`
126
126
127
127
- 2.3.0+
128
-
- only used in `createBundleRenderer`
128
+
- 只用于 `createBundleRenderer`
129
129
- Expects: `boolean | 'once'` (`'once'` only supported in 2.3.1+)
130
130
131
-
By default, for each render the bundle renderer will create a fresh V8 context and re-execute the entire bundle. This has some benefits - for example, the app code is isolated from the server process and we don't need to worry about the [stateful singleton problem](./structure.md#avoid-stateful-singletons) mentioned in the docs. However, this mode comes at some considerable performance cost because re-executing the bundle is expensive especially when the app gets bigger.
This option defaults to `true`for backwards compatibility, but it is recommended to use `runInNewContext: false`or`runInNewContext: 'once'` whenever you can.
> In 2.3.0 this option has a bug where `runInNewContext: false`still executes the bundle using a separate global context. The following information assumes version 2.3.1+.
With`runInNewContext: false`, the bundle code will run in the same `global`context with the server process, so be careful about code that modifies `global`in your application code.
With`runInNewContext: 'once'` (2.3.1+), the bundle is evaluated in a separate `global` context, however only once at startup. This provides better app code isolation since it prevents the bundle from accidentally polluting the server process' `global`object. The caveats are that:
139
+
使用`runInNewContext: 'once'` (2.3.1+),bundle 将在独立的`全局`上下文(separate global context)取值,然而只在启动时取值一次。这提供了更好的应用程序代码隔离,因为它防止 bundle 意外污染服务器进程的 `global`对象。注意事项如下:
140
140
141
-
1.Dependencies that modifies `global` (e.g. polyfills) cannot be externalized in this mode;
142
-
2.Values returned from the bundle execution will be using different global constructors, e.g. an error caught inside the bundle will not be an instance of `Error`in the server process.
Explicitly declare the base directory for the server bundle to resolve `node_modules`dependencies from. This is only needed if your generated bundle file is placed in a different location from where the externalized NPM dependencies are installed, or your `vue-server-renderer`is npm-linked into your current project.
Provide a [component cache](./caching.md#component-level-caching) implementation. The cache object must implement the following interface (using Flow notations):
@@ -174,14 +174,14 @@ See [Introducing the Server Bundle](./bundle-renderer.md) and [Build Configurati
174
174
})
175
175
```
176
176
177
-
Note that the cache object should at least implement `get`and`set`. In addition, `get`and`has`can be optionally async if they accept a second argument as callback. This allows the cache to make use of async APIs, e.g. a redis client:
@@ -194,40 +194,40 @@ See [Introducing the Server Bundle](./bundle-renderer.md) and [Build Configurati
194
194
195
195
-#### `directives`
196
196
197
-
Allows you to provide server-side implementations for your custom directives:
197
+
对于自定义指令,允许提供服务器端实现:
198
198
199
199
```js
200
200
constrenderer=createRenderer({
201
201
directives: {
202
202
example (vnode, directiveMeta) {
203
-
//transform vnode based on directive binding metadata
203
+
//基于指令绑定元数据(metadata)转换 vnode
204
204
}
205
205
}
206
206
})
207
207
```
208
208
209
-
As an example, check out [`v-show`'s server-side implementation](https://github.com/vuejs/vue/blob/dev/src/platforms/web/server/directives/show.js).
0 commit comments