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
> These directives can bind themselves to a property on the Vue instance, or to an expression which is evaluated in the context of the instance. When the value of the underlying property or expression changes, the `update()` function of these directives will be called asynchronously on next tick.
<pclass="tip">Using `v-html` with user-supplied data can be dangerous. It is suggested that you only use `v-html` when you are absolutely sure about the security of the data source, or pipe it through a custom filter that sanitizes untrusted HTML.</p>
18
+
<pclass="tip">
19
+
在用户产生的数据中使用`v-html`比较危险。使用`v-html`时应确保数据的安全性,或通过自定义过滤器将不被信任的 HTML 内容进行处理。
20
+
</p>
21
21
22
22
### v-show
23
23
24
-
-This directive can trigger transitions.
24
+
-本指令可以触发动画效果。
25
25
26
-
Set the element's display to `none` or its original value, depending on the truthy-ness of the binding's value.
26
+
根据绑定的真实值将元素的 display 属性设置为`none`或它的原始值。
27
27
28
28
### v-class
29
29
30
-
- This directive accepts an optional argument.
31
-
32
-
If no argument is provided, it will add the binding's value to the element's classList, and update the class as the value changes.
30
+
- 本元素接受配置参数
33
31
34
-
If a directive argument is provided, the argument will be the class to be toggled depending on the binding value's truthy-ness. Combined with multiple clauses this can be pretty useful:
@@ -43,32 +43,35 @@ If a directive argument is provided, the argument will be the class to be toggle
43
43
44
44
### v-attr
45
45
46
-
-This directive requires an argument.
46
+
-本指令需要一个参数
47
47
48
-
Updates the element's given attribute (indicated by the argument).
49
-
50
-
**Example:**
48
+
更新元素的指定属性(更新的属性由参数指定)
49
+
**例子:**
51
50
52
51
```html
53
52
<canvasv-attr="width:w, height:h"></canvas>
54
53
```
55
54
56
-
Internally, {{ Mustache }} interpolations inside attributes are compiled into computed `v-attr` directives.
57
55
58
-
<pclass="tip">You should use `v-attr` instead of mustache binding when setting the `src` attribute on `<img>` elements. Your templates are parsed by the browser before being compiled by Vue.js, so the mustache binding will cause a 404 when the browser tries to fetch it as the image's URL.</p>
<pclass="tip">It is recommended to use `v-style` instead of mustache bindings inside `style` attribute because Internet Explorer, regardless of version, will remove invalid inline styles when parsing the HTML.</p>
- This directive requires the value to be a Function or a statement.
117
+
- 本指令需要一个参数名。
118
+
- 本指令所需的值应该是一个函数或者声明。
119
+
120
+
121
+
为元素添加一个事件监听器。事件的类型由参数名来表示。这也是唯一可以和`key`过滤器一起使用的指令。详细请见[Listening for Events](../guide/events.html)。
114
122
115
-
Attaches an event listener to the element. The event type is denoted by the argument. It is also the only directive that can be used with the `key` filter. For more details see [Listening for Events](../guide/events.html).
116
123
117
124
### v-model
118
125
119
-
- This directive can only be used on `<input>`, `<select>` or `<textarea>` elements.
Create a two-way binding on a form input element. Data is synced on every `input` event by default. For detailed examples see [Handling Forms](../guide/forms.html).
Conditionally insert / remove the element based on the truthy-ness of the binding value. If the element is a `<template>` element, its content will be extracted as the conditional block.
@@ -136,7 +144,7 @@ Conditionally insert / remove the element based on the truthy-ness of the bindin
136
144
</template>
137
145
```
138
146
139
-
Will render:
147
+
渲染结果:
140
148
141
149
```html
142
150
<!--v-if-start-->
@@ -147,17 +155,17 @@ Will render:
147
155
148
156
### v-repeat
149
157
150
-
-This directive creates child Vue instances.
151
-
-This directive requires the value to be an Array, Object or Number.
152
-
-This directive can trigger transitions.
153
-
-This directive accepts an optional argument.
154
-
-Directive params: `trackby`
158
+
-本指令会创建子 Vue 实例。
159
+
-本指令的值应为一个数组、对象或数字。
160
+
-本指令可以触发动画效果。
161
+
-本指令接受一个配置参数。
162
+
-指令的参数:`trackby`
155
163
156
-
Create a child ViewModel for every item in the binding Array or Object. If the value is a whole Number then that many child ViewModels are created. These child ViewModels will be automatically created / destroyed when mutating methods, e.g. `push()`, are called on the Array or Object, or the number is increased or decreased.
157
164
158
-
When no argument is provided, the child ViewModel will directly use the assigned element in the Array as its `$data`. If the value is not an object, a wrapper data object will be created and the value will be set on that object using the alias key `$value`.
@@ -167,8 +175,7 @@ When no argument is provided, the child ViewModel will directly use the assigned
167
175
</ul>
168
176
```
169
177
170
-
If an argument is provided, a wrapper data object will always be created, using the argument string as the alias key. This allows for more explicit property access in templates:
@@ -177,18 +184,18 @@ If an argument is provided, a wrapper data object will always be created, using
177
184
</ul>
178
185
```
179
186
180
-
For detailed examples, see[Displaying a List](../guide/list.html).
187
+
查看详细的例子,点这里[Displaying a List](../guide/list.html).
181
188
182
189
### v-with
183
190
184
-
-This directive can only be used with `v-component`.
185
-
-This directive accepts only keypaths, no expressions.
191
+
-本指令只能与`v-component`一起使用。
192
+
-本指令只接受 keypaths, 而不是表达式。
186
193
187
-
Allows a child ViewModel to inherit data from the parents. You can either pass in an Object which will be used as the `data` option, or bind individual parent properties to the child with different keys. This directive must be used in combination with `v-component`.
The data inheritance is one-way: when parent property changes, the child will be notified of the change and update accordingly; however if the child sets the property to something else, it will not affect the parent, and the modified property will be overwritten the next time parent property changes.
<!-- you can access properties with the new keys -->
@@ -218,71 +224,71 @@ Example inheriting individual properties (using the same data):
218
224
219
225
### v-events
220
226
221
-
-This directive can only be used with `v-component`.
222
-
-This directive accepts only keypaths, no expressions.
227
+
-本指令只能与`v-component`一起使用
228
+
-本指令只接受 keypaths, 而不是表达式。
223
229
224
-
Allows a parent instance to listen to events on a child instance. The difference from `v-on` is that `v-events` listens to Vue's component system events created via `vm.$emit()` rather than DOM events. This directive allows more decoupled parent-child communication without having to hard-code event listeners into the parent component. Note that it can only be used together with `v-component`, i.e. on the root element of a child component.
230
+
允许一个父 Vue 实例监听一个子 Vue 实例上的事件。不同于`v-on`的是,`v-events`监听的是通过`vm.$emit()`创建的 Vue 组件系统事件,而不是 DOM 事件。本指令让父子通信进一步解耦,不需要在父组件中“硬编写”事件监听器。需要注意的是,本指令只能与`v-component`同时使用,即只能用在子组件的根元素上。
When the child component calls `this.$emit('change', ...)`, the parent's `onChildChange` method will be invoked with additional arguments passed to `$emit()`.
> Literal directives treat their attribute value as a plain string; they do not attempt to bind themselves to anything. All they do is executing the `bind()` function with the string value once. Literal directives accept mustache expressions inside their value, but these expressions will be evaluated only once on first compile and do not react to data changes.
Compile this element as a child ViewModel with a registered component constructor. This can be used with `v-with` to inehrit data from the parent. For more details see [Component System](../guide/components.html).
Register a reference to a child component on its parent for easier access. Only respected when used in combination with `v-component` or `v-repeat`. The component instance will be accessible on its parent's `$` object. For an example, see [child reference](../guide/components.html#Child_Reference).
<!-- content will change based on vm.partialId -->
263
270
<divv-partial="{{partialId}}"></div>
264
271
```
265
272
266
-
You can also use this syntax (which doesn't support reactivity):
267
-
273
+
你也可以使用这样的语法(不支持相应数据改变)。
268
274
```html
269
275
<div>{{> my-partial}}</div>
270
276
```
271
277
272
278
### v-transition
273
279
274
-
Notify Vue.js to apply transitions to this element. The transition classes are applied when certain transition-triggering directives modify the element, or when the Vue instance's DOM manipulation methods are called.
280
+
通知 Vue.js 为元素应用动画效果。动画 class 将会在某些能触发过渡的指令修改了元素时或当 Vue 实例中操作 DOM 的方法被调用时引用到元素上。
281
+
详情请见[the guide on transitions](../guide/transitions.html).
275
282
276
-
For details, see [the guide on transitions](../guide/transitions.html).
277
283
278
-
## Empty Directives
284
+
## 空指令
279
285
280
-
> Empty directives do not require and will ignore their attribute value.
286
+
> 空指令不需要参数,并且会忽略它的属性值。
281
287
282
288
### v-pre
283
289
284
-
Skip compilation for this element and all its children. Skipping large numbers of nodes with no directives on them can speed up compilation.
290
+
跳过编译此元素和此元素所有的子元素。跳过大量没有指令的节点可以加快编译速度。
285
291
286
292
### v-cloak
287
293
288
-
This property remains on the element until the associated ViewModel finishes compilation. Combined with CSS rules such as `[v-cloak] { display: none }`, this directive can be used to hide un-compiled mustache bindings until the ViewModel is ready.
0 commit comments