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>

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM