File tree Expand file tree Collapse file tree 10 files changed +58
-12
lines changed
conditionals-and-loops/App Expand file tree Collapse file tree 10 files changed +58
-12
lines changed Original file line number Diff line number Diff line change 3
3
< button @click ="list.pop() "> Pop Number</ button >
4
4
< button @click ="list.reverse() "> Reverse List</ button >
5
5
6
- < ul v-if ="show ">
6
+ < ul v-if ="show && list.length ">
7
7
< li v-for ="item of list "> {{ item }}</ li >
8
8
</ ul >
9
+ < p v-else-if ="list.length "> List is not empty, but hidden.</ p >
10
+ < p v-else > List is empty.</ p >
Original file line number Diff line number Diff line change @@ -7,13 +7,15 @@ export default {
7
7
const checkedNames = ref ( [ 'Jack' ] )
8
8
const picked = ref ( 'One' )
9
9
const selected = ref ( 'A' )
10
+ const multiSelected = ref ( [ 'A' ] )
10
11
11
12
return {
12
13
text,
13
14
checked,
14
15
checkedNames,
15
16
picked,
16
- selected
17
+ selected,
18
+ multiSelected
17
19
}
18
20
}
19
21
}
Original file line number Diff line number Diff line change @@ -5,7 +5,8 @@ export default {
5
5
checked : true ,
6
6
checkedNames : [ 'Jack' ] ,
7
7
picked : 'One' ,
8
- selected : 'A'
8
+ selected : 'A' ,
9
+ multiSelected : [ 'A' ]
9
10
}
10
11
}
11
12
}
Original file line number Diff line number Diff line change @@ -5,6 +5,10 @@ <h2>Checkbox</h2>
5
5
< input type ="checkbox " id ="checkbox " v-model ="checked " />
6
6
< label for ="checkbox "> Checked: {{ checked }}</ label >
7
7
8
+ <!--
9
+ multiple checkboxes can bind to the same
10
+ array v-model value
11
+ -->
8
12
< h2 > Multi Checkbox</ h2 >
9
13
< input type ="checkbox " id ="jack " value ="Jack " v-model ="checkedNames " />
10
14
< label for ="jack "> Jack</ label >
@@ -31,3 +35,11 @@ <h2>Select</h2>
31
35
< option > C</ option >
32
36
</ select >
33
37
< 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 >
Original file line number Diff line number Diff line change @@ -5,16 +5,19 @@ export default {
5
5
const message = ref ( 'Hello World!' )
6
6
7
7
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.
12
10
message . value = message . value . split ( '' ) . reverse ( ) . join ( '' )
13
11
}
14
12
13
+ function notify ( ) {
14
+ alert ( 'navigation was prevented.' )
15
+ }
16
+
15
17
return {
16
18
message,
17
- reverseMessage
19
+ reverseMessage,
20
+ notify
18
21
}
19
22
}
20
23
}
Original file line number Diff line number Diff line change @@ -7,6 +7,9 @@ export default {
7
7
methods : {
8
8
reverseMessage ( ) {
9
9
this . message = this . message . split ( '' ) . reverse ( ) . join ( '' )
10
+ } ,
11
+ notify ( ) {
12
+ alert ( 'navigation was prevented.' )
10
13
}
11
14
}
12
- }
15
+ }
Original file line number Diff line number Diff line change
1
+ button , a {
2
+ display : block;
3
+ margin-bottom : 1em ;
4
+ }
Original file line number Diff line number Diff line change
1
+ <!--
2
+ Note we don't need .value inside templates because
3
+ refs are automatically "unwrapped" in templates.
4
+ -->
1
5
< h1 > {{ message }}</ h1 >
2
6
3
- <!-- bind to a method/function -->
7
+ <!--
8
+ Bind to a method/function.
9
+ The @click syntax is short for v-on:click.
10
+ -->
4
11
< button @click ="reverseMessage "> Reverse Message</ button >
5
12
6
- <!-- can also be an inline expression statement -->
13
+ <!-- Can also be an inline expression statement -->
7
14
< 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 >
Original file line number Diff line number Diff line change 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.
Original file line number Diff line number Diff line change 7
7
< span v-if ="isFolder "> [{{ isOpen ? '-' : '+' }}]</ span >
8
8
</ div >
9
9
< 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
+ -->
10
14
< TreeItem
11
15
class ="item "
12
16
v-for ="model in model.children "
You can’t perform that action at this time.
0 commit comments