Skip to content

Commit fa08035

Browse files
committed
improve examples
1 parent 67a6025 commit fa08035

File tree

10 files changed

+58
-12
lines changed

10 files changed

+58
-12
lines changed

src/examples/src/conditionals-and-loops/App/template.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
<button @click="list.pop()">Pop Number</button>
44
<button @click="list.reverse()">Reverse List</button>
55

6-
<ul v-if="show">
6+
<ul v-if="show && list.length">
77
<li v-for="item of list">{{ item }}</li>
88
</ul>
9+
<p v-else-if="list.length">List is not empty, but hidden.</p>
10+
<p v-else>List is empty.</p>

src/examples/src/form-bindings/App/composition.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ export default {
77
const checkedNames = ref(['Jack'])
88
const picked = ref('One')
99
const selected = ref('A')
10+
const multiSelected = ref(['A'])
1011

1112
return {
1213
text,
1314
checked,
1415
checkedNames,
1516
picked,
16-
selected
17+
selected,
18+
multiSelected
1719
}
1820
}
1921
}

src/examples/src/form-bindings/App/options.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ export default {
55
checked: true,
66
checkedNames: ['Jack'],
77
picked: 'One',
8-
selected: 'A'
8+
selected: 'A',
9+
multiSelected: ['A']
910
}
1011
}
1112
}

src/examples/src/form-bindings/App/template.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ <h2>Checkbox</h2>
55
<input type="checkbox" id="checkbox" v-model="checked" />
66
<label for="checkbox">Checked: {{ checked }}</label>
77

8+
<!--
9+
multiple checkboxes can bind to the same
10+
array v-model value
11+
-->
812
<h2>Multi Checkbox</h2>
913
<input type="checkbox" id="jack" value="Jack" v-model="checkedNames" />
1014
<label for="jack">Jack</label>
@@ -31,3 +35,11 @@ <h2>Select</h2>
3135
<option>C</option>
3236
</select>
3337
<span>Selected: {{ selected }}</span>
38+
39+
<h2>Multi Select</h2>
40+
<select v-model="multiSelected" multiple style="width:100px">
41+
<option>A</option>
42+
<option>B</option>
43+
<option>C</option>
44+
</select>
45+
<span>Selected: {{ multiSelected }}</span>

src/examples/src/handling-input/App/composition.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,19 @@ export default {
55
const message = ref('Hello World!')
66

77
function reverseMessage() {
8-
// in JavaScript, we must access/mutate the value of a ref
9-
// via its .value property.
10-
// Note we don't need to do so inside templates because
11-
// refs are automatically "unwrapped" in templates.
8+
// Access/mutate the value of a ref via
9+
// its .value property.
1210
message.value = message.value.split('').reverse().join('')
1311
}
1412

13+
function notify() {
14+
alert('navigation was prevented.')
15+
}
16+
1517
return {
1618
message,
17-
reverseMessage
19+
reverseMessage,
20+
notify
1821
}
1922
}
2023
}

src/examples/src/handling-input/App/options.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ export default {
77
methods: {
88
reverseMessage() {
99
this.message = this.message.split('').reverse().join('')
10+
},
11+
notify() {
12+
alert('navigation was prevented.')
1013
}
1114
}
12-
}
15+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
button, a {
2+
display: block;
3+
margin-bottom: 1em;
4+
}
Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
1+
<!--
2+
Note we don't need .value inside templates because
3+
refs are automatically "unwrapped" in templates.
4+
-->
15
<h1>{{ message }}</h1>
26

3-
<!-- bind to a method/function -->
7+
<!--
8+
Bind to a method/function.
9+
The @click syntax is short for v-on:click.
10+
-->
411
<button @click="reverseMessage">Reverse Message</button>
512

6-
<!-- can also be an inline expression statement -->
13+
<!-- Can also be an inline expression statement -->
714
<button @click="message += '!'">Append "!"</button>
15+
16+
<!--
17+
Vue also provides modifiers for common tasks
18+
such as e.preventDefault() and e.stopPropagation()
19+
-->
20+
<a href="https://vuejs.org" @click.prevent="notify">
21+
A link with e.preventDefault()
22+
</a>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
This example demonstrates handling user input with the v-on directive. The @click syntax is short for v-on:click.
1+
This example demonstrates handling user input with the v-on directive.

src/examples/src/tree/TreeItem/template.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
<span v-if="isFolder">[{{ isOpen ? '-' : '+' }}]</span>
88
</div>
99
<ul v-show="isOpen" v-if="isFolder">
10+
<!--
11+
A component can recursively render itself using its
12+
"name" option (inferred from filename if using SFC)
13+
-->
1014
<TreeItem
1115
class="item"
1216
v-for="model in model.children"

0 commit comments

Comments
 (0)