Vue.js火速上手第六章——v-model在其他元素及类型上的用法

一、v-model在input标签中单选框的使用

在单选框type="radio"中的使用

		

{ {location}}

var app=new Vue({
		el: '#app',
		data:{
			location:'大连',
		},
});

初始效果:

Vue.js火速上手第六章——v-model在其他元素及类型上的用法_第1张图片

点击了“沈阳”选项后,效果如下:

Vue.js火速上手第六章——v-model在其他元素及类型上的用法_第2张图片  

二、v-model在input标签中多选框的使用

 在复选框type="checkbox"中的使用

		
		
		
		

{ {location}}

 由于是多选框,所以location变量要定义为一个数组,我们设定初始值为“沈阳”

var app=new Vue({
		el: '#app',
		data:{
			location:['沈阳'],
		},
});
 

初始效果如下:

Vue.js火速上手第六章——v-model在其他元素及类型上的用法_第3张图片 

再选上“大连”、“北京” 

Vue.js火速上手第六章——v-model在其他元素及类型上的用法_第4张图片

三、 v-model在textarea中的使用

		
		

{ {state}}

var app=new Vue({
		el: '#app',
		data:{
			state:'this is the end of the story',
		},
});

初始效果:

Vue.js火速上手第六章——v-model在其他元素及类型上的用法_第5张图片

修改内容时,外部同步修改

Vue.js火速上手第六章——v-model在其他元素及类型上的用法_第6张图片 

四、  v-model在下拉框中的使用

	
		

{ {food}}

var app=new Vue({
		el: '#app',
		data:{	
			food: 4,
		},
});

初始效果:

Vue.js火速上手第六章——v-model在其他元素及类型上的用法_第7张图片

做了选择后,效果如下: 

Vue.js火速上手第六章——v-model在其他元素及类型上的用法_第8张图片 

五、  v-model在多选下拉框中的使用

		
		

{ {drink}}

var app=new Vue({
		el: '#app',
		data:{
			drink: [],
		},
});

初始效果:

Vue.js火速上手第六章——v-model在其他元素及类型上的用法_第9张图片

选择了其中的三个后:

Vue.js火速上手第六章——v-model在其他元素及类型上的用法_第10张图片 

六、本篇完整代码

main.js

var app=new Vue({
		el: '#app',
		data:{
			location:['沈阳'],
			state:'this is the end of the story',
			food: 1,
			drink: [],
		},
});

 index.html


	
	    
		chapter18.5
	
			
		

{ {location}}

{ {state}}

{ {food}}

{ {drink}}

 

你可能感兴趣的:(Vue.js,vue.js)