Skip to content

Commit 2f91616

Browse files
dear-lizhihuayyx990803
authored andcommitted
Translate api.md via GitLocalize
1 parent 5a9688c commit 2f91616

File tree

1 file changed

+54
-54
lines changed

1 file changed

+54
-54
lines changed

zh/api.md

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## `createRenderer([options])`
44

5-
Create a [`Renderer`](#class-renderer) instance with (optional) [options](#renderer-options).
5+
使用(可选的)[选项](#renderer-options)创建一个 [`Renderer`](#class-renderer) 实例。
66

77
```js
88
const { createRenderer } = require('vue-server-renderer')
@@ -11,20 +11,20 @@ const renderer = createRenderer({ ... })
1111

1212
## `createBundleRenderer(bundle[, options])`
1313

14-
Create a [`BundleRenderer`](#class-bundlerenderer) instance with a server bundle and (optional) [options](#renderer-options).
14+
使用 server bundle 和(可选的)[选项](#renderer-options)创建一个 [`BundleRenderer`](#class-bundlerenderer) 实例。
1515

1616
```js
1717
const { createBundleRenderer } = require('vue-server-renderer')
1818
const renderer = createBundleRenderer(serverBundle, { ... })
1919
```
2020

21-
The `serverBundle` argument can be one of the following:
21+
`serverBundle` 参数可以是以下之一:
2222

2323
- 绝对路径,指向一个已经构建好的 bundle 文件(`.js``.json`)。必须以 `/` 开头才会被识别为文件路径。
24-
- A bundle object generated by webpack + `vue-server-renderer/server-plugin`.
25-
- A string of JavaScript code (not recommended).
24+
- webpack + `vue-server-renderer/server-plugin` 生成的 bundle 对象。
25+
- JavaScript 代码字符串(不推荐)。
2626

27-
See [Introducing the Server Bundle](./bundle-renderer.md) and [Build Configuration](./build-config.md) for more details.
27+
更多细节请查看 [Server Bundle 指引](./bundle-renderer.md) [构建配置](./build-config.md)
2828

2929
## `Class: Renderer`
3030

@@ -34,59 +34,59 @@ See [Introducing the Server Bundle](./bundle-renderer.md) and [Build Configurati
3434

3535
- #### `renderer.renderToStream(vm[, context])`
3636

37-
Render a Vue instance to a Node.js stream. The context object is optional. See [Streaming](./streaming.md) for more details.
37+
Vue 示例渲染为 Node.js 流(stream)。上下文对象(context object)可选。更多细节请查看[流式渲染](./streaming.md)
3838

3939
## `Class: BundleRenderer`
4040

4141
- #### `bundleRenderer.renderToString([context, ]callback)`
4242

43-
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.
43+
bundle 渲染为字符串。上下文对象(context object)可选。回调是一个典型的Node.js样式回调,其中第一个参数是错误,第二个参数是呈现的字符串。
4444

4545
- #### `bundleRenderer.renderToStream([context])`
4646

47-
Render the bundle to a Node.js stream. The context object is optional. See [Streaming](./streaming.md) for more details.
47+
bundle 渲染为 Node.js 流(stream). 上下文对象(context object)可选。更多细节请查看[流式渲染](./streaming.md)
4848

49-
## Renderer Options
49+
## Renderer 选项
5050

5151
- #### `template`
5252

5353
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.
5454

55-
The template also supports basic interpolation using the render context:
55+
模板还支持使用渲染上下文(render context)进行基本插值:
5656

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)。
5959

60-
The template automatically injects appropriate content when certain data is found on the render context:
60+
当在渲染上下文(render context)找到某些数据时,模板会自动注入合适的内容:
6161

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.
62+
- `context.head`:(字符串)任意 head 标记(markup),将注入到页面头部。
63+
- `context.styles`:(字符串)任意内联 CSS,将注入到页面头部。注意,如果对组件 CSS 使用 `vue-loader` + `vue-style-loader`,此属性将自动填充。
64+
- `context.state`:(对象)初始 Vuex store 状态,将作为 `window.__INITIAL_STATE__` 内联到页面。内联的 JSON 将使用 [serialize-javascript](https://github.com/yahoo/serialize-javascript) 自动清理,以防止 XSS 攻击。
6565

66-
In addition, when `clientManifest` is also provided, the template automatically injects the following:
66+
此外,当提供 `clientManifest` 时,模板会自动注入以下内容:
6767

68-
- Client-side JavaScript and CSS assets needed by the render (with async chunks automatically inferred);
68+
- 渲染所需的客户端 JavaScript CSS 资源(使用异步 chunk 自动推断);
6969
- Optimal `<link rel="preload/prefetch">` resource hints for the rendered page.
7070

71-
You can disable all automatic injections by also passing `inject: false` to the renderer.
71+
你也可以通过将 `inject: false` 传递给 renderer,来禁用所有自动注入。
7272

73-
See also:
73+
具体查看:
7474

75-
- [Using a Page Template](./basic.md#using-a-page-template)
76-
- [Manual Asset Injection](./build-config.md#manual-asset-injection)
75+
- [使用一个页面模板](./basic.md#using-a-page-template)
76+
- [手动资源注入(Manual Asset Injection)](./build-config.md#manual-asset-injection)
7777
- #### `clientManifest`
7878
- 2.3.0+
7979

80-
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).
80+
生成由 `vue-server-renderer/client-plugin` 生成的客户端构建 manifest 对象(client build manifest object)。客户端 manifest 对象(client manifest)通过「向 HTML 模板自动资源注入」可以为 bundle renderer 提供合适信息。更多详细信息,请查看[生成 clientManifest](./build-config.md#generating-clientmanifest)
8181

8282
-
8383
#### `inject`
8484

8585
- 2.3.0+
8686

87-
Controls whether to perform automatic injections when using `template`. Defaults to `true`.
87+
控制使用 `template` 时是否执行自动注入。默认是 `true`
8888

89-
See also: [Manual Asset Injection](./build-config.md#manual-asset-injection).
89+
参考:[手动资源注入(Manual Asset Injection)](./build-config.md#manual-asset-injection)
9090

9191
-
9292
#### `shouldPreload`
@@ -95,16 +95,16 @@ See [Introducing the Server Bundle](./bundle-renderer.md) and [Build Configurati
9595

9696
A function to control what files should have `<link rel="preload">` resource hints generated.
9797

98-
By default, only JavaScript and CSS files will be preloaded, as they are absolutely needed for your application to boot.
98+
默认情况下,只有 JavaScript CSS 文件会被预加载,因为它们是引导应用程序所必需的。
9999

100-
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:
100+
对于其他类型的资源(如图像或字体),预加载过多可能会浪费带宽,甚至损害性能,因此预加载什么资源具体依赖于场景。你可以使用 `shouldPreload` 选项精确控制预加载资源:
101101

102102
```js
103103
const renderer = createBundleRenderer(bundle, {
104104
template,
105105
clientManifest,
106106
shouldPreload: (file, type) => {
107-
// type is inferred based on the file extension.
107+
// 基于文件扩展名的类型推断。
108108
// https://fetch.spec.whatwg.org/#concept-request-destination
109109
if (type === 'script' || type === 'style') {
110110
return true
@@ -125,35 +125,35 @@ See [Introducing the Server Bundle](./bundle-renderer.md) and [Build Configurati
125125
#### `runInNewContext`
126126

127127
- 2.3.0+
128-
- only used in `createBundleRenderer`
128+
- 只用于 `createBundleRenderer`
129129
- Expects: `boolean | 'once'` (`'once'` only supported in 2.3.1+)
130130

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.
131+
默认情况下,对于每次渲染,bundle renderer 将创建一个新的 V8 上下文并重新执行整个 bundle。这具有一些好处 - 例如,应用程序代码与服务器进程隔离,我们无需担心文档中提到的[状态单例问题](./structure.md#avoid-stateful-singletons)。然而,这种模式有一些相当大的性能开销,因为重新执行 bundle 带来 高性能开销,特别是当应用程序很大时。
132132

133-
This option defaults to `true` for backwards compatibility, but it is recommended to use `runInNewContext: false` or `runInNewContext: 'once'` whenever you can.
133+
此选项默认为 `true` 用于向后兼容,但建议你尽可能使用 `runInNewContext: false` `runInNewContext: 'once'`
134134

135-
> 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+.
135+
> 2.3.0 中,此选项有一个 bug,其中 `runInNewContext: false` 仍然使用独立的全局上下文(separate global context)执行 bundle。以下信息假定版本为 2.3.1+
136136
137-
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.
137+
使用 `runInNewContext: false`bundle 代码将与服务器进程在同一个 `global` 上下文中运行,所以请留意在应用程序代码中,会修改 `global` 的代码。
138138

139-
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` 对象。注意事项如下:
140140

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.
141+
1. 在此模式下,修改 `global`(例如,polyfill)的依赖模块不能进行外部暴露;
142+
2. bundle 执行返回的值将使用不同的全局构造函数,例如,在服务器进程中捕获到 bundle 的内部错误,不会是 `Error` 的一个实例。
143143

144-
See also: [Source Code Structure](./structure.md)
144+
参考:[源码结构](./structure.md)
145145

146146
-
147147
#### `basedir`
148148

149149
- 2.2.0+
150-
- only used in `createBundleRenderer`
150+
- 只用于 `createBundleRenderer`
151151

152-
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.
152+
显式地声明 server bundle 的基本目录(base directory),以从 `node_modules` 解析依赖模块。只有在所生成的 bundle 文件与外部的 NPM 依赖模块放置在不同位置,或者 `vue-server-renderer` 是通过 npm-linked 链接当前项目中时,才需要配置。
153153

154154
- #### `cache`
155155

156-
Provide a [component cache](./caching.md#component-level-caching) implementation. The cache object must implement the following interface (using Flow notations):
156+
提供[组件缓存](./caching.md#component-level-caching)具体实现。缓存对象必须实现以下接口(使用 Flow 记号):
157157

158158
```js
159159
type RenderCache = {
@@ -163,7 +163,7 @@ See [Introducing the Server Bundle](./bundle-renderer.md) and [Build Configurati
163163
};
164164
```
165165

166-
A typical usage is passing in an [lru-cache](https://github.com/isaacs/node-lru-cache):
166+
典型用法是传入 [lru-cache](https://github.com/isaacs/node-lru-cache)
167167

168168
```js
169169
const LRU = require('lru-cache')
@@ -174,14 +174,14 @@ See [Introducing the Server Bundle](./bundle-renderer.md) and [Build Configurati
174174
})
175175
```
176176

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:
177+
请注意,缓存对象应至少要实现 `get` `set`。此外,如果 `get` `has` 接收第二个参数作为回调,那 `get``has` 也可以是可选的异步函数。这允许缓存使用异步 API,例如,一个 redis 客户端:
178178

179179
```js
180180
const renderer = createRenderer({
181181
cache: {
182182
get: (key, cb) => {
183183
redisClient.get(key, (err, res) => {
184-
// handle error if any
184+
// 处理任何错误
185185
cb(res)
186186
})
187187
},
@@ -194,40 +194,40 @@ See [Introducing the Server Bundle](./bundle-renderer.md) and [Build Configurati
194194

195195
- #### `directives`
196196

197-
Allows you to provide server-side implementations for your custom directives:
197+
对于自定义指令,允许提供服务器端实现:
198198

199199
```js
200200
const renderer = createRenderer({
201201
directives: {
202202
example (vnode, directiveMeta) {
203-
// transform vnode based on directive binding metadata
203+
// 基于指令绑定元数据(metadata)转换 vnode
204204
}
205205
}
206206
})
207207
```
208208

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).
209+
例如,请查看 [`v-show` 的服务器端实现](https://github.com/vuejs/vue/blob/dev/src/platforms/web/server/directives/show.js)
210210

211-
## webpack Plugins
211+
## webpack 插件
212212

213-
The webpack plugins are provided as standalone files and should be required directly:
213+
webpack 插件作为独立文件提供,并且应当直接 require:
214214

215215
```js
216216
const VueSSRServerPlugin = require('vue-server-renderer/server-plugin')
217217
const VueSSRClientPlugin = require('vue-server-renderer/client-plugin')
218218
```
219219

220-
The default files generated are:
220+
生成的默认文件是:
221221

222-
- `vue-ssr-server-bundle.json` for the server plugin;
223-
- `vue-ssr-client-manifest.json` for the client plugin.
222+
- `vue-ssr-server-bundle.json` 用于服务器端插件;
223+
- `vue-ssr-client-manifest.json` 用于客户端插件。
224224

225-
The filenames can be customized when creating the plugin instances:
225+
创建插件实例时可以自定义文件名:
226226

227227
```js
228228
const plugin = new VueSSRServerPlugin({
229229
filename: 'my-server-bundle.json'
230230
})
231231
```
232232

233-
See [Build Configuration](./build-config.md) for more information.
233+
更多信息请查看[构建配置](./build-config.md)

0 commit comments

Comments
 (0)