019——VUE中v-for与computer结合功能实例讲解

<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>v-for与computer结合功能实例讲解</title>
		<script src="vue.js"></script>
	</head>

	<body>
		<div id="lantian">
			<li v-for="v in stus">
				{{v.name}}--{{v.sex}}
			</li>
			{{type}}
			<input type="radio" v-model="type" value="girl" />女孩
			<input type="radio" v-model="type" value="boy" />男孩
		</div>

		<script>
			var app = new Vue({
				el: '#lantian',
				computed: {
					stus() {
						if(this.type == 'all') {
							return this.user;
						} else {
							return this.user.filter((v) => {
								return v.sex == this.type;
							});
						}
					}
				},
				data: {
					type: 'all',
					user: [{
							name: '小王',
							sex: 'boy'
						},
						{
							name: '小明',
							sex: 'boy'
						},
						{
							name: '小李',
							sex: 'girl'
						},
						{
							name: '小梅',
							sex: 'girl'
						}
					]
				}
			});
		</script>
	</body>

</html>

  

posted @ 2017-12-21 14:08  生如逆旅,一苇以航  阅读(2431)  评论(0编辑  收藏  举报