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
Set a property on an object. If the object is reactive, ensure the property is created as a reactive property and trigger view updates. This is primarily used to get around the limitation that Vue cannot detect property additions.
178
168
179
169
**注意对象不能是 Vue 实例,或者 Vue 实例的根数据对象**
180
-
**Note the object cannot be a Vue instance, or the root data object of a Vue instance.**
Delete a property on an object. If the object is reactive, ensure the deletion triggers view updates. This is primarily used to get around the limitation that Vue cannot detect property deletions, but you should rarely need to use it.
194
182
195
183
**注意对象不能是 Vue 实例,或者 Vue 实例的根数据对象**
196
-
**Note the object cannot be a Vue instance, or the root data object of a Vue instance.**
197
184
198
185
-**参考:**[深入响应式原理](/guide/reactivity.html)
199
186
@@ -206,11 +193,9 @@ type: api
206
193
-**用法:**
207
194
208
195
注册或获取全局指令。
209
-
Register or retrieve a global directive.
210
196
211
197
```js
212
198
// 注册
213
-
// register
214
199
Vue.directive('my-directive', {
215
200
bind:function () {},
216
201
inserted:function () {},
@@ -220,14 +205,11 @@ type: api
220
205
})
221
206
222
207
// 注册(传入一个简单的指令函数)
223
-
// register (simple function directive)
224
208
Vue.directive('my-directive', function () {
225
209
// 这里将会被 `bind` 和 `update` 调用
226
-
// this will be called as `bind` and `update`
227
210
})
228
211
229
212
// getter,返回已注册的指令
230
-
// getter, return the directive definition if registered
Install a Vue.js plugin. If the plugin is an Object, it must expose an `install` method. If it is a function itself, it will be treated as the install method. The install method will be called with Vue as the argument.
295
269
296
270
当 install 方法被同一个插件多次调用,插件将只会被安装一次。
297
-
When this method is called on the same plugin multiple times, the plugin will be installed only once.
Apply a mixin globally, which affects every Vue instance created afterwards. This can be used by plugin authors to inject custom behavior into components. **Not recommended in application code**.
310
282
311
283
-**参考:**[全局混合](/guide/mixins.html#Global-Mixin)
312
284
@@ -318,7 +290,6 @@ type: api
318
290
-**用法:**
319
291
320
292
在render函数中编译模板字符串。**只在独立构建时有效**
321
-
Compiles a template string into a render function. **Only available in the standalone build.**
322
293
323
294
```js
324
295
var res =Vue.compile('<div><span>{{ msg }}</span></div>')
@@ -345,38 +316,30 @@ type: api
345
316
-**细节:**
346
317
347
318
Vue 实例的数据对象。Vue 将会递归将 data 的属性转换为 getter/setter,从而让 data 的属性能够响应数据变化。**对象必须是普通对象**:浏览器 API 创建的原生对象,原型上的属性会被忽略。大概来说,data 应该只能是数据 - 不推荐观察拥有状态行为的对象。
348
-
The data object for the Vue instance. Vue will recursively convert its properties into getter/setters to make it "reactive". **The object must be plain**: native objects such as browser API objects and prototype properties are ignored. A rule of thumb is that data should just be data - it is not recommended to observe objects with its own stateful behavior.
Once observed, you can no longer add reactive properties to the root data object. It is therefore recommended to declare all root-level reactive properties upfront, before creating the instance.
352
321
353
322
实例创建之后,可以通过 `vm.$data` 访问原始数据对象。Vue 实例也代理了 data 对象上所有的属性,因此访问 `vm.a` 等价于访问 `vm.$data.a`。
354
-
After the instance is created, the original data object can be accessed as `vm.$data`. The Vue instance also proxies all the properties found on the data object, so `vm.a` will be equivalent to `vm.$data.a`.
Properties that start with `_` or `$` will **not** be proxied on the Vue instance because they may conflict with Vue's internal properties and API methods. You will have to access them as `vm.$data._property`.
When defining a **component**, `data` must be declared as a function that returns the initial data object, because there will be many instances created using the same definition. If we still use a plain object for `data`, that same object will be **shared by reference** across all instances created! By providing a `data` function, every time a new instance is created, we can simply call it to return a fresh copy of the initial data.
<pclass="tip">Note that __you should not use an arrow function with the `data` property__ (e.g. `data: () => { return { a: this.myProp }}`). The reason is arrow functions bind the parent context, so `this` will not be the Vue instance as you expect and `this.myProp` will be undefined.</p>
A list/hash of attributes that are exposed to accept data from the parent component. It has a simple Array-based syntax and an alternative Object-based syntax that allows advanced configurations such as type checking, custom validation and default values.
399
360
400
361
-**示例:**
401
362
402
363
```js
403
364
// 简单语法
404
-
// simple syntax
405
365
Vue.component('props-demo-simple', {
406
366
props: ['size', 'myMessage']
407
367
})
408
368
409
369
// 对象语法,提供校验
410
-
// object syntax with validation
411
370
Vue.component('props-demo-advanced', {
412
371
props: {
413
372
// 只检测类型
414
-
// just type check
415
373
height:Number,
416
374
// 检测类型 + 其他验证
417
-
// type check plus other validations
418
375
age: {
419
376
type:Number,
420
377
default:0,
@@ -434,12 +391,10 @@ type: api
434
391
-**类型:**`{ [key: string]: any }`
435
392
436
393
-**限定:** 只用于 `new` 创建的实例中。
437
-
-**Restriction:** only respected in instance creation via `new`.
438
394
439
395
-**细节:**
440
396
441
397
创建实例时传递 props。主要作用是方便测试。
442
-
Pass props to an instance during its creation. This is primarily intended to make unit testing easier.
443
398
444
399
-**示例:**
445
400
@@ -463,13 +418,10 @@ type: api
463
418
-**细节:**
464
419
465
420
计算属性将被混入到 Vue 实例中。getter 和 setter 的 this 上下文自动地绑定为 Vue 实例。
466
-
Computed properties to be mixed into the Vue instance. All getters and setters have their `this` context automatically bound to the Vue instance.
<pclass="tip">Note that __you should not use an arrow function to define a computed property__ (e.g. `aDouble: () => this.a * 2`). The reason is arrow functions bind the parent context, so `this` will not be the Vue instance as you expect and `this.a` will be undefined.</p>
470
423
471
424
计算属性的结果会被缓存,除非依赖的响应式属性变化才会重新计算。
472
-
Computed properties are cached, and only re-computed on reactive dependency changes.
473
425
474
426
-**示例:**
475
427
@@ -478,12 +430,10 @@ type: api
478
430
data: { a:1 },
479
431
computed: {
480
432
// 仅读取,值只须为函数
481
-
// get only, just need a function
482
433
aDouble:function () {
483
434
returnthis.a*2
484
435
},
485
436
// 读取和设置
486
-
// both get and set
487
437
aPlus: {
488
438
get:function () {
489
439
returnthis.a+1
@@ -510,10 +460,8 @@ type: api
510
460
-**细节:**
511
461
512
462
methods 将被混入到 Vue 实例中。可以直接通过 VM 实例访问这些方法,或者在指令表达式中使用。方法中的 `this` 自动绑定为 Vue 实例。
513
-
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.
<pclass="tip">Note that __you should not use an arrow function to define a method__ (e.g. `plus: () => this.a++`). The reason is arrow functions bind the parent context, so `this` will not be the Vue instance as you expect and `this.a` will be undefined.</p>
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, or an Object that contains additional options. The Vue instance will call `$watch()` for each entry in the object at instantiation.
<pclass="tip">Note that __you should not use an arrow function to define a watcher__ (e.g. `searchQuery: newValue => this.updateAutocomplete(newValue)`). The reason is arrow functions bind the parent context, so `this` will not be the Vue instance as you expect and `this.updateAutocomplete` will be undefined.</p>
0 commit comments