1
2
3
4
|
<
div
id
=
"app"
>
<
h1
>{{message}}
h1
>
<
input
type
=
"text"
v-model
=
"message"
/>
div
>
|
1
2
3
4
5
6
|
new
Vue({
el:
'#app'
,
data:{
message:
'Hello World !'
}
})
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
<
div
id
=
"text"
>
<
p
>Multiline message is: {{msg}}
p
>
<
textarea
v-model
=
"msg"
>
textarea
>
div
>
<
script
src
=
"https://unpkg.com/vue/dist/vue.js"
>
script
>
<
script
>
var vm = new Vue({
el:'#text',
data:{
msg:''
}
})
script
>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
<
div
id
=
"app"
>
<
input
type
=
"checkbox"
id
=
"checkbox"
v-model
=
"checked"
>
<
label
for
=
"checkbox"
>{{checked}}
label
>
div
>
<
script
src
=
"https://unpkg.com/vue/dist/vue.js"
>
script
>
<
script
>
var vm1 = new Vue({
el:'#app',
data:{
checked:true
}
});
script
>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
var
vm1 =
new
Vue({
el:
'#app'
,
data:{
checked:
true
}
});
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
<
div
id
=
"app2"
>
<
input
type
=
"radio"
id
=
"male"
value
=
"male"
v-model
=
"gender"
>
<
label
for
=
"male"
>Male
label
>
<
input
type
=
"radio"
id
=
"female"
value
=
"female"
v-model
=
"gender"
>
<
label
for
=
"female"
>Female
label
>
<
p
>Gender: {{gender}}
p
>
div
>
<
script
src
=
"https://unpkg.com/vue/dist/vue.js"
>
script
>
<
script
>
var vm3 = new Vue({
el:'#app2',
data:{
gender:''
}
});
script
>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
<
div
id
=
"app3"
>
<
select
v-model
=
"selected"
>
<
option
>A
option
>
<
option
>B
option
>
<
option
>C
option
>
select
>
<
p
>Selected: {{selected}}
p
>
div
>
<
script
src
=
"https://unpkg.com/vue/dist/vue.js"
>
script
>
<
script
>
var vm4 = new Vue({
el:'#app3',
data:{
selected:''
}
});
script
>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
<
div
id
=
"app4"
>
<
select
v-model
=
"selected"
multiple>
<
option
>A
option
>
<
option
>B
option
>
<
option
>C
option
>
select
>
<
p
>Selected: {{selected}}
p
>
div
>
<
script
src
=
"https://unpkg.com/vue/dist/vue.js"
>
script
>
<
script
>
var vm5 = new Vue({
el:'#app4',
data:{
selected:[]
}
});
script
>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
<
div
id
=
"app5"
>
<
select
v-model
=
"selected"
>
<
option
v-for
=
"option in options"
v-bind:value
=
"option.value"
>{{option.text}}
option
>
select
>
<
p
>Selected: {{selected}}
p
>
div
>
<
script
src
=
"https://unpkg.com/vue/dist/vue.js"
>
script
>
<
script
>
var vm6 = new Vue({
el:'#app5',
data:{
selected:'A',
options:[
{text:'One', value:'A'},
{text:'Two', value:'B'},
{text:'Three', value:'C'}
]
}
});
script
>
|
1
2
3
4
5
6
7
8
9
10
|
<
input
type
=
"radio"
v-model
=
"picked"
value
=
"a"
>
<
input
type
=
"checkbox"
v-model
=
"toggle"
>
<
select
v-model
=
"selected"
>
<
option
value
=
"abc"
>ABC
option
>
select
>
|
1
2
3
4
5
6
7
8
9
|
<
div
id
=
"app1"
>
<
input
type
=
"checkbox"
v-model
=
"toggle"
v-bind:true-value
=
"a"
v-bind:false-value
=
"b"
>
div
>
// 当选中时
vm.toggle === vm.a
// 当没有选中时
vm.toggle === vm.b
|
1
2
3
|
<
input
type
=
"radio"
v-model
=
"pick"
v-bind:value
=
"a"
>
// 当选中时vm.pick === vm.a
|
1
2
3
4
5
6
7
8
|
<
select
v-model
=
"selected"
>
<
option
v-bind:value
=
"{ number: 123 }"
>123
option
>
select
>
// 当选中时
typeof vm.selected // -> 'object'
vm.selected.number // -> 123
|
1
2
3
4
5
6
7
|
<
div
id
=
"app"
>
<
h1
>{{message}}
h1
>
<
input
type
=
"text"
v-model
=
"message"
/>
<
pre
>
{{$data|json}}
pre
>
div
>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
new
Vue({
el:
'#app'
,
data:{
msg:
'仅处理number类型的数字'
}
})
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
new
Vue({
el:
'#app'
,
data:{
msg:
'内容是在change事件后才改变的'
}
})
|
1
2
3
4
5
6
7
8
9
10
11
12
|
new
Vue({
el:
'#app'
,
data:{
msg:
'内容是在5s后才改变的'
}
})
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
<
div
id
=
"app1"
>
<
input
v-model
=
"msg1"
type
=
"text"
>
<
p
>The common message is: {{msg1}}
p
>
<
hr
>
<
input
v-model.trim
=
"msg2"
type
=
"text"
>
<
p
>The trim message is: {{msg2}}
p
>
div
>
<
script
src
=
"https://unpkg.com/vue/dist/vue.js"
>
script
>
<
script
>
var vm1 = new Vue({
el:'#app1',
data:{
msg1:'',
msg2:''
}
})
|