Skip to content

Commit 2c61266

Browse files
committed
feedback for template-syntax.md
1 parent 57abed8 commit 2c61266

File tree

1 file changed

+36
-5
lines changed

1 file changed

+36
-5
lines changed

src/guide/essentials/template-syntax.md

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ The double mustaches interprets the data as plain text, not HTML. In order to ou
3434
<p>Using v-html directive: <span v-html="rawHtml"></span></p>
3535
</div>
3636

37+
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+
3739
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.
3840

3941
:::warning Security Warning
@@ -48,7 +50,7 @@ Mustaches cannot be used inside HTML attributes. Instead, use a [`v-bind` direct
4850
<div v-bind:id="dynamicId"></div>
4951
```
5052

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.
5254

5355
### Shorthand
5456

@@ -74,7 +76,34 @@ The `disabled` attribute will be included if `isButtonDisabled` has a [truthy va
7476

7577
### Dynamically Binding Multiple Attributes
7678

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+
<div class="composition-api">
82+
83+
```js
84+
const objectOfAttrs = {
85+
id: 'container',
86+
class: 'wrapper'
87+
}
88+
```
89+
90+
</div>
91+
<div class="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:
78107

79108
```vue-html
80109
<div v-bind="objectOfAttrs"></div>
@@ -99,7 +128,7 @@ These expressions will be evaluated as JavaScript in the data scope of the curre
99128
In Vue templates, JavaScript expressions can be used in the following positions:
100129

101130
- 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-`)
103132

104133
### Expressions Only
105134

@@ -135,9 +164,9 @@ Globals not explicitly included in the list, for example user-attached propertie
135164

136165
## Directives
137166

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.
139168

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:
141170

142171
```vue-html
143172
<p v-if="seen">Now you see me</p>
@@ -210,6 +239,8 @@ Dynamic argument expressions have some syntax constraints because certain charac
210239
<a :['foo' + bar]="value"> ... </a>
211240
```
212241

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+
213244
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:
214245

215246
```vue-html

0 commit comments

Comments
 (0)