-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b954e08
commit ff1bc0b
Showing
2 changed files
with
7 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<h1>Make me red</h1> <!-- 此处添加一个动态 class 绑定 --> | ||
<h1>Make me red</h1> <!-- 此處添加一個動態 class 綁定 --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
# Attribute 绑定 {#attribute-bindings} | ||
# 屬性綁定 {#attribute-bindings} | ||
|
||
在 Vue 中,mustache 语法 (即双大括号) 只能用于文本插值。为了给 attribute 绑定一个动态值,需要使用 `v-bind` 指令: | ||
在 Vue 中,mustache 語法 (即雙大括號) 只能用於文本插值。為了給屬性綁定一個動態值,需要使用 `v-bind` 指令: | ||
|
||
```vue-html | ||
<div v-bind:id="dynamicId"></div> | ||
``` | ||
|
||
**指令**是由 `v-` 开头的一种特殊 attribute。它们是 Vue 模板语法的一部分。和文本插值类似,指令的值是可以访问组件状态的 JavaScript 表达式。关于 `v-bind` 和指令语法的完整细节请详阅<a target="_blank" href="/guide/essentials/template-syntax.html">指南 - 模板语法</a>。 | ||
**指令**是由 `v-` 開頭的一種特殊屬性。它們是 Vue 模板語法的一部分。和文本插值類似,指令的值是可以訪問組件狀態的 JavaScript 表達式。關於 `v-bind` 和指令語法的完整細節請詳閱<a target="_blank" href="/guide/essentials/template-syntax.html">指南 - 模板語法</a>。 | ||
|
||
冒号后面的部分 (`:id`) 是指令的“参数”。此处,元素的 `id` attribute 将与组件状态里的 `dynamicId` 属性保持同步。 | ||
冒號後面的部分 (`:id`) 是指令的“參數”。此處,元素的 `id` attribute 將與組件狀態裡的 `dynamicId` 屬性保持同步。 | ||
|
||
由于 `v-bind` 使用地非常频繁,它有一个专门的简写语法: | ||
由於 `v-bind` 使用地非常頻繁,它有一個專門的簡寫語法: | ||
|
||
```vue-html | ||
<div :id="dynamicId"></div> | ||
``` | ||
|
||
现在,试着把一个动态的 `class` 绑定添加到这个 `<h1>` 上,并使用 `titleClass` 的<span class="options-api">数据属性</span><span class="composition-api"> ref </span>作为它的值。如果绑定正确,文字将会变为红色。 | ||
現在,試著把一個動態的 `class` 綁定添加到這個 `<h1>` 上,並使用 `titleClass` 的<span class="options-api">數據屬性</span><span class="composition-api"> ref </span>作為它的值。如果綁定正確,文字將會變為紅色。 |