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
Here we're encountering something new. The `v-html` attribute you're seeing is called a **directive**. Directives are prefixed with `v-` to indicate that they are special attributes provided by Vue, and as you may have guessed, they apply special reactive behavior to the rendered DOM. Here, we're basically saying "keep this element's inner HTML up-to-date with the `rawHtml` property on the current active instance."
38
+
37
39
The contents of the `span` will be replaced with the value of the `rawHtml` property, interpreted as plain HTML - data bindings are ignored. Note that you cannot use `v-html` to compose template partials, because Vue is not a string-based templating engine. Instead, components are preferred as the fundamental unit for UI reuse and composition.
38
40
39
41
:::warning Security Warning
@@ -48,7 +50,7 @@ Mustaches cannot be used inside HTML attributes. Instead, use a [`v-bind` direct
48
50
<div v-bind:id="dynamicId"></div>
49
51
```
50
52
51
-
If the bound value is `null` or `undefined` then the attribute will not be included on the rendered element.
53
+
The `v-bind` directive instructs Vue to keep the element's `id` attribute in sync with the component's `dynamicId` property. If the bound value is `null` or `undefined`, then the attribute will be removed from the rendered element.
52
54
53
55
### Shorthand
54
56
@@ -74,7 +76,34 @@ The `disabled` attribute will be included if `isButtonDisabled` has a [truthy va
74
76
75
77
### Dynamically Binding Multiple Attributes
76
78
77
-
If you have a JavaScript object representing multiple attributes to be bound on an element, you can use `v-bind` without an argument:
79
+
If you have a JavaScript object representing multiple attributes that looks like this:
80
+
81
+
<divclass="composition-api">
82
+
83
+
```js
84
+
constobjectOfAttrs= {
85
+
id:'container',
86
+
class:'wrapper'
87
+
}
88
+
```
89
+
90
+
</div>
91
+
<divclass="options-api">
92
+
93
+
```js
94
+
data() {
95
+
return {
96
+
objectOfAttrs: {
97
+
id:'container',
98
+
class:'wrapper'
99
+
}
100
+
}
101
+
}
102
+
```
103
+
104
+
</div>
105
+
106
+
You can bind them to a single element by using `v-bind` without an argument:
78
107
79
108
```vue-html
80
109
<div v-bind="objectOfAttrs"></div>
@@ -99,7 +128,7 @@ These expressions will be evaluated as JavaScript in the data scope of the curre
99
128
In Vue templates, JavaScript expressions can be used in the following positions:
100
129
101
130
- Inside text interpolations (mustaches)
102
-
- In the attribute value of any `v-` directive bindings (including shorthands)
131
+
- In the attribute value of any Vue directives (special attributes that start with `v-`)
103
132
104
133
### Expressions Only
105
134
@@ -135,9 +164,9 @@ Globals not explicitly included in the list, for example user-attached propertie
135
164
136
165
## Directives
137
166
138
-
Directives are special attributes with the `v-` prefix. Vue provides a number of [built-in directives](/api/built-in-directives.html), including `v-bind` which we have introduced above.
167
+
Directives are special attributes with the `v-` prefix. Vue provides a number of [built-in directives](/api/built-in-directives.html), including `v-html` and `v-bind` which we have introduced above.
139
168
140
-
Directive attribute values are expected to be single JavaScript expressions (with the exception of `v-for`and `v-on`, which will be discussed later). A directive's job is to reactively apply updates to the DOM when the value of its expression changes. Take [`v-if`](/api/built-in-directives.html#v-if) as an example:
169
+
Directive attribute values are expected to be single JavaScript expressions (with the exception of `v-for`, `v-on`and `v-slot`, which will be discussed in their respective sections later). A directive's job is to reactively apply updates to the DOM when the value of its expression changes. Take [`v-if`](/api/built-in-directives.html#v-if) as an example:
141
170
142
171
```vue-html
143
172
<p v-if="seen">Now you see me</p>
@@ -210,6 +239,8 @@ Dynamic argument expressions have some syntax constraints because certain charac
210
239
<a :['foo' + bar]="value"> ... </a>
211
240
```
212
241
242
+
If you need to pass a complex dynamic argument, it's probably better to use to a [computed property](./computed.html), which we will cover shortly.
243
+
213
244
When using in-DOM templates (templates directly written in an HTML file), you should also avoid naming keys with uppercase characters, as browsers will coerce attribute names into lowercase:
0 commit comments