8000 tranlsated api/options by @etanxing · poorprogrammer/vuejs.org@d82f034 · GitHub
[go: up one dir, main page]

Skip to content

Commit d82f034

Browse files
author
勾股
committed
tranlsated api/options by @etanxing
1 parent 2a51148 commit d82f034

File tree

1 file changed

+81
-82
lines changed

1 file changed

+81
-82
lines changed

source/api/options.md

Lines changed: 81 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ order: 2
77

88
### data
99

10-
- **Type:** `Object | Function`
11-
- **Restricton:** Only accepts `Function` when used in `Vue.extend()`.
10+
- **类型:** `Object | Function`
11+
- **局限:** `Vue.extend()`只接受`Function`.
1212

13-
The data object for the Vue instance. It can be accessed as `vm.$data`:
13+
Vue实例的数据对象. 可以通过`vm.$data`访问:
1414

1515
```js
1616
var data = { a: 1 }
@@ -20,7 +20,7 @@ var vm = new Vue({
2020
vm.$data === data // -> true
2121
```
2222

23-
The Vue instance will proxy access to all its properties, therefore you can manipulate the properties on the Vue instance and the changes get synced back to the actual data object:
23+
Vue实例会通过代理方法访问它的所有属性,因此你可以给Vue实例添加属性,然后这些变化会同步到数据对象里:
2424

2525
```js
2626
vm.a // -> 1
@@ -30,9 +30,9 @@ data.a = 3
3030
vm.a // -> 3
3131
```
3232

33-
The object must be JSON-compliant (no circular references). You can use it just like an ordinary object, and it will look exactly the same when serialized with `JSON.stringify`. You can also share it between multiple Vue instances.
33+
数据对象必须是JSON格式 (不能有循环引用). 就像普通对象一样使用,而且支持`JSON.stringify`并可以在不同Vue实例中分享.
3434

35-
A special case here is when using the `data` option in `Vue.extend()`. Since we don't want nested objects to be shared by all instances created from that extended constructor, we must provide a function that returns a fresh copy of the default data:
35+
这里有一个特殊的情况,就是传递`data`参数到`Vue.extend()`时. 因为我们不想让嵌套对象被所有通过`Vue.extend()`扩展而生成实例共享,所以必须提供一个函数来返回一个数据对象的副本:
3636

3737
``` js
3838
var MyComponent = Vue.extend({
@@ -47,15 +47,15 @@ var MyComponent = Vue.extend({
4747
})
4848
```
4949

50-
<p class="tip">Under the hood, Vue.js attaches a hidden property `__ob__` and recursively converts the object's enumerable properties into getters and setters to enable dependency collection. Properties with keys that starts with `$` or `_` are skipped.</p>
50+
<p class="tip">在内部, Vue.js会创建一个隐藏属性`__ob__`, 然后通过递归循环转换所有可枚举的属性到getters和setters开实现依赖收集. 以`$``_`开头的属性会被跳过.</p>
5151

5252
### methods
5353

54-
- **Type:** `Object`
54+
- **类型:** `Object`
5555

56-
Methods to be mixed into the Vue instance. You can access these methods directly on the VM instance, or use them in directive expressions. All methods will have their `this` context automatically bound to the Vue instance.
56+
Methods是被mixed到Vue实例. 你可以通过VM实例访问这些方法,或者在指令表达式里使用他们. 所有方法的`this`就是Vue实例本身.
5757

58-
**Example:**
58+
**例子:**
5959

6060
```js
6161
var vm = new Vue({
@@ -72,11 +72,11 @@ vm.a // 2
7272

7373
### computed
7474

75-
- **Type:** `Object`
75+
- **类型:** `Object`
7676

77-
Computed properties to be mixed into the Vue instance. All getters and setters have their `this` context automatically bound to the Vue instance.
77+
Computed的属性是被mixed到Vue实例. 所有getters和setters的`this`就是Vue实例本身.
7878

79-
**Example:**
79+
**例子:**
8080

8181
```js
8282
var vm = new Vue({
@@ -105,11 +105,11 @@ vm.aDouble // -> 4
105105

106106
### paramAttributes
107107

108-
- **Type:** `Array`
108+
- **类型:** `Array`
109109

110-
An array of attribute names to be set on the Vue instance as initial data. Useful when passing data to a component.
110+
paramAttributes是一个数组。每个成员会被创建在Vue实例作为初始数据. 一般用来传递数据到一个组件.
111111

112-
**Example:**
112+
**例子:**
113113

114114
``` js
115115
Vue.component('param-demo', {
@@ -124,157 +124,156 @@ Vue.component('param-demo', {
124124
``` html
125125
<param-demo size="100" message="hello!"></param-demo>
126126
```
127-
128-
Param attributes can also contain interpolation tags. The interpolation will be evaluated against the parent, and under the hood they will be compiled as [`v-with`](../api/directives.html#v-with), which means when the value of the interpolated expression changes, the component's corresponding property will also be updated:
127+
参数属性也可以包含interpolation标签。Interpolation标签将以父组件为实例来解析,这实际是由[`v-with`](../api/directives.html#v-with)完成的,也就是意味着如果interpolation表达式的值改变了,组件相关联的属性也会被更新:
129128

130129
``` html
131130
<param-demo message="{&#123;parentMessage&#125;}"></param-demo>
132131
```
133132

134-
#### Notes on hyphened attributes
133+
#### `-` 属性注意事项
135134

136-
HTML attribute names ignore upper and lower case differences, so we usually use hyphened attributes instead of camel case. There are some special cases when using `paramAttributes` with attributes that contains hyphens:
135+
HTML属性名是不区分大小写的,所以我们用`-`而不是camel case。使用带`-``paramAttributes`,这里有一些特殊情况:
137136

138-
1. If the attribute is a data attribute, the `data-` prefix will be auto stripped;
137+
1. 如果属性是一个数据属性,`data-`前缀会自动去掉;
139138

140-
2. If the attribute still contains dashes, it will be camelized. This is because it's inconvenient to access top level properties containing dashes in templates: the expression `my-param` will be parsed as a minus expression unless you use the awkward `this['my-param']` syntax.
139+
2. 如果属性还包含`-`,它将会被camelized,这是因为在模板中访问带`-`的顶级属性是不方便的:表达式`my-param`将会解析成一个减法操作的表达式,除非你使用这种语法`this['my-param']`
141140

142-
This means a param attribute `data-hello` will be set on the vm as `vm.hello`; And `my-param` will be set as `vm.myParam`.
141+
这意味着参数属性`data-hello`将会被设置在vm的`vm.hello`对象上;然后`my-param`将会变成`vm.myParam`
143142

144143
## DOM
145144

146145
### el
147146

148-
- **Type:** `String | HTMLElement | Function`
149-
- **Restriction:** only accepts type `Function` when used in `Vue.extend()`.
147+
- **类型:** `String | HTMLElement | Function`
148+
- **限制:** 使用`Vue.extend()`时只接受`Function`类型。
150149

151-
Provide the Vue instance with an existing DOM element. It can be a CSS selector string, an actual HTMLElement, or a function that returns an HTMLElement. The resolved element will be accessible as `vm.$el`.
150+
给Vue实例提供一个DOM元素。它可以是一个CSS选择器,一个HTMLElement,或一个返回HTMLElement的函数。处理过的元素可以通过`vm.$el`访问.
152151

153-
When used in `Vue.extend`, a function must be provided so each instance gets a separately created element.
152+
当用`Vue.extend`,必须使用函数返回一个有效值,来保证每个实例得到一个独立的元素。
154153

155-
If the option is available at instantiation, the instance will immediately enter compilation; otherwise, the user will have to explicitly call `vm.$mount()` to manually start the compilation.
154+
如果初始化的时候就提供了,那就马上进行编译;否则,只有执行了`vm.$mount()`才开始编译。
156155

157156
### template
158157

159-
- **Type:** `String`
158+
- **类型:** `String`
160159

161-
A string template to be inserted into `vm.$el`. Any existing markup inside `vm.$el` will be overwritten, unless [content insertion points](../guide/components.html#内容插入) are present in the template. If the **replace** option is `true`, the template will replace `vm.$el` entirely.
160+
一个被插入到`vm.$el`的字符串模板。任何`vm.$el`的内容都会被覆盖,除非模板里有[内容插入点](../guide/components.html#Content_Insertion)。如果**replace**选项是`true`,模板会完全替换`vm.$el`
162161

163162
If it starts with `#` it will be used as a querySelector and use the selected element's innerHTML and the template string. This allows the use of the common `<script type="x-template">` trick to include templates.
164163

165-
<p class="tip">Vue.js uses DOM-based templating. The compiler walks through DOM elements and looks for directives and creates data bindings. This means all Vue.js templates are parsable HTML that can be converted into actual DOM elements by the browser. Vue.js converts string templates into DOM fragments so they can be cloned when creating more Vue instances. If you want your templates to be valid HTML, you can configure the directive prefix to start with `data-`.</p>
164+
<p class="tip">Vue.js使用基于DOM的模板体系。编译器走遍所有DOM元素去找指令描述来绑定数据。这就意味着所有的Vue.js模板都是可以转成浏览器可以识别的DOM元素。Vue.js转化字符串模板到DOM fragments,所以他们可以被复制在创建更多Vue实例的时候。如果你想你的模板是有效的HTML,你可以设置指令表达式的前缀是`data-`</p>
166165

167166
### replace
168167

169-
- **Type:** `Boolean`
170-
- **Default:** `false`
171-
- **Restriction:** only respected if the **template** option is also present.
168+
- **类型:** `Boolean`
169+
- **缺省值:** `false`
170+
- **限制:** 只有提供**template**选项的时候
172171

173-
Whether to replace the original `vm.$el` with the template's content instead of appending to it.
172+
是否用模板内容替换原始的`vm.$el`而不是附加上。
174173

175174
## Lifecycle
176175

177-
All lifecycle hooks have their `this` context bound to the Vue instance they belong to. The Vue instance will also fire corresponding events for each hook in the form of `"hook:<hookName>"`. e.g. for `created`, a `"hook:created"` event will be fired.
176+
所有的生命周期的`this`都Vue实例。Vue实例也有对应的事件,以`"hook:<hookName>"`的形式。例如为`created`触发一个`hook:created`
178177

179178
### created
180179

181-
- **Type:** `Function`
180+
- **类型:** F987 `Function`
182181

183-
Called synchronously after the instance is created. At this stage, the instance has finished processing the options which means the following have been set up: data observation, computed properties, methods, watch/event callbacks. However, DOM compilation has not been started, and the `$el` property will not be available yet.
182+
在实例被创建的时候同步调用。在这个阶段,实例完成了包含以下内容的预处理:数据健康,数据监控,计算属性,方法,监控事件回调。但DOM编译还没开始,`$el`还不可用。
184183

185184
### beforeCompile
186185

187-
- **Type:** `Function`
186+
- **类型:** `Function`
188187

189-
Called right before the compilation starts.
188+
在编译之前调用。
190189

191190
### compiled
192191

193-
- **Type:** `Function`
192+
- **类型:** `Function`
194193

195-
Called after the compilation is finished. At this stage all directives have been linked so data changes will trigger DOM updates. However, `$el` is not guaranteed to have been inserted into the document yet.
194+
编译完成后调用,在这个阶段,所有的指令都绑定,数据变化会触发DOM更新。但不能保证`$el`已经被插入到DOM中。
196195

197196
### ready
198197

199-
- **Type:** `Function`
198+
- **类型:** `Function`
200199

201-
Called after compilation **and** the `$el` is **inserted into the document for the first time**. Note this insertion must be executed via Vue (with methods like `vm.$appendTo()` or as a result of a directive update) to trigger the `ready` hook.
200+
当完成编译**而且**`$el`也第一次的插入到DOM中了之后调用。注意这个插入必须要通过Vue完成的(例如`vm.$appendTo()`的方法或者是一个指令更新的结果)来触发的`ready`事件。
202201

203202
### attached
204203

205-
- **Type:** `Function`
204+
- **类型:** `Function`
206205

207-
Called when `vm.$el` is attached to DOM by a directive or a VM instance method such as `$appendTo()`. Direct manipulation of `vm.$el` will **not** trigger this hook.
206+
`vm.$el`被一个指令或是VM实例方法(例如`$appendTo()`)添加到DOM里的时候调用。直接操作`vm.$el`**不会**出发这个事件。
208207

209208
### detached
210209

211-
- **Type:** `Function`
210+
- **类型:** `Function`
212211

213-
Called when `vm.$el` is removed from the DOM by a directive or a VM instance method. Direct manipulation of `vm.$el` will **not** trigger this hook.
212+
`vm.$el`被一个指令或是VM实例方法从DOM里删除的时候调用。直接操作`vm.$el`**不会**出发这个事件。
214213

215214
### beforeDestroy
216215

217-
- **Type:** `Function`
216+
- **类型:** `Function`
218217

219-
Called right before a Vue instance is destroyed. At this stage the instance is still fully functional.
218+
在一个Vue实例被销毁之前调用。这个时候,实例的绑定和指令仍工作正常。
220219

221220
### destroyed
222221

223-
- **Type:** `Function`
222+
- **类型:** `Function`
224223

225-
Called after a Vue instance has been destroyed. When this hook is called, all bindings and directives of the Vue instance have been unbound and all child Vue instances have also been destroyed.
224+
在一个Vue实例被销毁之后调用。如果被执行,所有的Vue实例的绑定和指令都会被解除绑定,所有子组件也会被销毁.
226225

227-
Note if there is a leaving transition, the `destroyed` hook is called **after** the transition has finished.
226+
注意如果有一个leaving transition`destroyed`被执行在transition结束**之后**.
228227

229228
## Assets
230229

231-
These are private assets that will be available only to this Vue instance and its children during compilation.
230+
这里有一些Vue实例和它的子实例在编译期有效的私有的资源。
232231

233232
### directives
234233

235-
- **Type:** `Object`
234+
- **类型:** `Object`
236235

237-
A hash of directives to be made available to the Vue instance. For details on how to write a custom directive, see [Writing Custom Directives](../guide/custom-directive.html).
236+
一个指令的哈希表。更多看[Writing Custom Directives](../guide/custom-directive.html).
238237

239238
### filters
240239

241-
- **Type:** `Object`
240+
- **类型:** `Object`
242241

243-
A hash of filters to be made available to the Vue instance. For details on how to write a custom filter, see [Writing Custom Filters](../guide/custom-filter.html).
242+
一个过滤器的哈希表。更多看[Writing Custom Filters](../guide/custom-filter.html).
244243

245244
### components
246245

247-
- **Type:** `Object`
246+
- **类型:** `Object`
248247

249-
A hash of components to be made available to the Vue instance. For details on how to extend and compose Vue instances, see [Component System](../guide/components.html).
248+
一个组件的哈希表。更多看[Component System](../guide/components.html).
250249

251250
### partials
252251

253-
- **Type:** `Object`
252+
- **类型:** `Object`
254253

255-
A hash of partials to be made available to the Vue instance. Also see [v-partial](../api/directives.html#v-partial).
254+
一个partial的哈希表。更多看[v-partial](../api/directives.html#v-partial)
256255

257256
### transitions
258257

259-
- **Type:** `Object`
258+
- **类型:** `Object`
260259

261-
A hash of transitions to be made available to the Vue instance. For details see the guide on [Transitions](../guide/transitions.html).
260+
一个transition的哈希表。详细看[Transitions](../guide/transitions.html)
262261

263262
## Others
264263

265264
### inherit
266265

267-
- **Type:** `Boolean`
266+
- **类型:** `Boolean`
268267
- **Default:** `false`
269268

270-
Whether to inherit parent scope data. Set it to `true` if you want to create a component that inherits parent scope. When `inherit` is set to `true`, you can:
269+
是否继承父组件的数据. 如果你想从父组件继承数据,就设成`true``inherit``true`的时候你可以:
271270

272-
1. Bind to parent scope properties in the component template;
273-
2. Directly access parent properties on the component instance itself, via prototypal inheritance.
271+
1. 在当先组件模板里绑定父组件的数据属性;
272+
2. 直接访问父组件的属相(通过prototypal继承)。
274273

275-
One important thing to know when using `inherit: true` is that **the child can also set parent properties**, because all Vue instance data properties are getter/setters.
274+
重要的是,当用`inherit: true`**子组件也可以改变父组件的属性值**,因为所有Vue实例的数据都是getter/setters
276275

277-
**Example:**
276+
**例子:**
278277

279278
``` js
280279
var parent = new Vue({
@@ -294,9 +293,9 @@ parent.a // -> 2
294293

295294
### events
296295

297-
An object where keys are events to listen for and values are the corresponding callbacks. Note these are Vue events rather than DOM events. The value can also be a string of a method name. The Vue instance will call `$on()` for each entry in the object at instantiation.
296+
Events对象的key是事件名,值就是相应的回调函数值。注意,这是Vue的事件不是DOM事件。值也可以是一个方法名。Vue实例会在初始化的时候对每一个events对象的属性执行`$on()`
298297

299-
**Example:**
298+
**例子:**
300299

301300
``` js
302301
var vm = new Vue({
@@ -322,11 +321,11 @@ vm.$emit('bye') // -> goodbye!
322321

323322
### watch
324323

325-
- **Type**: `Object`
324+
- **类型**: `Object`
326325

327-
An object where keys are expressions to watch and values are the corresponding callbacks. The value can also be a string of a method name. The Vue instance will call `$watch()` for each entry in the object at instantiation.
326+
Watch对象的key是表达式,值就是相应的回调函数值。值也可以是个方法名。Vue实例会在初始化的时候对每一个watch对象的属性执行`$watch()`
328327

329-
**Example:**
328+
**例子:**
330329

331330
``` js
332331
var vm = new Vue({
@@ -344,11 +343,11 @@ vm.a = 2 // -> new: 2, old: 1
344343

345344
### mixins
346345

347-
- **Type**: `Array`
346+
- **类型**: `Array`
348347

349-
The `mixins` option accepts an array of mixin objects. These mixin objects can contain instance options just like normal instance objects, and they will be merged against the eventual options using the same option merging logic in `Vue.extend()`. e.g. If your mixin contains a created hook and the component itself also has one, both functions will be called.
348+
`mixins`接受一个mixin对象数组. 就像正常的实例对象一样,这些mixin对象包含实例选项,而且他们也会被合并到最终的选项。e.g. 如果你加了一个created hook ,那么这个组件就会执行所有的created hook。
350349

351-
**Example:**
350+
**例子:**
352351

353352
``` js
354353
var mixin = {
@@ -364,12 +363,12 @@ var vm = new Vue({
364363

365364
### name
366365

367-
- **Type**: `String`
368-
- **Restrctions:** only respected when used in `Vue.extend()`.
366+
- **类型**: `String`
367+
- **限制:** 仅限使用 `Vue.extend()`的时候。
369368

370-
When inspecting an extended Vue component in the console, the default constructor name is `VueComponent`, which isn't very informative. By passing in an optional `name` option to `Vue.extend()`, you will get a better inspection output so that you know which component you are looking at. The string will be camelized and used as the component's constructor name.
369+
当在console里监视一个扩展过的Vue组件的时候,缺省构造函数名是`VueComponent`,但它并不是很有用。但你可以传一个可选项`name``Vue.extend()`,这样你就能知道你正在看那个组件。这个字符串或被camelized并作为组件的构造函数的名字使用。
371370

372-
**Example:**
371+
**例子:**
373372

374373
``` js
375374
var Ctor = Vue.extend({

0 commit comments

Comments
 (0)
0