Skip to content

Commit 1f5b2c9

Browse files
committed
2.6: more examples for dynamic arguments
1 parent 746f128 commit 1f5b2c9

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/v2/api/index.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2055,12 +2055,18 @@ type: api
20552055
<!-- method handler -->
20562056
<button v-on:click="doThis"></button>
20572057
2058+
<!-- dynamic event (2.6.0+) -->
2059+
<button v-on:[event]="doThis"></button>
2060+
20582061
<!-- inline statement -->
20592062
<button v-on:click="doThat('hello', $event)"></button>
20602063
20612064
<!-- shorthand -->
20622065
<button @click="doThis"></button>
20632066
2067+
<!-- shorthand dynamic event (2.6.0+) -->
2068+
<button @[event]="doThis"></button>
2069+
20642070
<!-- stop propagation -->
20652071
<button @click.stop="doThis"></button>
20662072
@@ -2131,9 +2137,15 @@ type: api
21312137
<!-- bind an attribute -->
21322138
<img v-bind:src="imageSrc">
21332139
2140+
<!-- dynamic attribute name (2.6.0+) -->
2141+
<button v-bind:[key]="value"></button>
2142+
21342143
<!-- shorthand -->
21352144
<img :src="imageSrc">
21362145
2146+
<!-- shorthand dynamic attribute name (2.6.0+) -->
2147+
<button :[key]="value"></button>
2148+
21372149
<!-- with inline string concatenation -->
21382150
<img :src="'/path/to/images/' + fileName">
21392151
@@ -2152,7 +2164,7 @@ type: api
21522164
<!-- DOM attribute binding with prop modifier -->
21532165
<div v-bind:text-content.prop="text"></div>
21542166
2155-
<!-- shorthand for prop modifier (2.6+) -->
2167+
<!-- shorthand for prop modifier (2.6.0+) -->
21562168
<div .text-content="text"></div>
21572169
21582170
<!-- prop binding. "prop" must be declared in my-component. -->

src/v2/guide/syntax.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,12 @@ The `v-` prefix serves as a visual cue for identifying Vue-specific attributes i
182182

183183
<!-- shorthand -->
184184
<a :href="url"> ... </a>
185+
186+
<!-- shorthand with dynamic argument (2.6.0+) -->
187+
<a :[key]="url"> ... </a>
185188
```
186189

187-
> New in 2.6
190+
> DOM Property Shorthand
188191
189192
In 2.6 a separate shorthand for explicit DOM property bindings (with the `.prop` modifier) have been introduced:
190193

@@ -204,6 +207,9 @@ In 2.6 a separate shorthand for explicit DOM property bindings (with the `.prop`
204207

205208
<!-- shorthand -->
206209
<a @click="doSomething"> ... </a>
210+
211+
<!-- shorthand with dynamic argument (2.6.0+) -->
212+
<a @[event]="doSomething"> ... </a>
207213
```
208214

209215
They may look a bit different from normal HTML, but `:` and `@` are valid chars for attribute names and all Vue.js supported browsers can parse it correctly. In addition, they do not appear in the final rendered markup. The shorthand syntax is totally optional, but you will likely appreciate it when you learn more about its usage later.

0 commit comments

Comments
 (0)