3.v-if,v-show,v-for 指令

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>v-if,v-show,v-for 指令</title>
		<!-- v-if: 当属性是false时,直接从dom中删除标签
		v-show: 当属性是false时,隐藏当前标签
		v-for: 循环展示一个list数据 -->
		<script src="./vue.js" type="text/javascript" charset="utf-8"></script>
	</head>
	<body>
		<div id="root">
			<div v-if="show">
				hello world
			</div>
			<button @click="handleClick">toggle</button>
			<ul>
				<!-- <li v-for="item of list" >{{item}}</li> -->
				<li v-for="(item,index) of list" :key="index">{{item}}</li>
				<!-- 在使用v-for时最好添加一个key,这样可以提高页面渲染速度,且key值要保持唯一不重复-->
			</ul>
		</div>
		<script type="text/javascript">
			new Vue({
				el: "#root",
				data:{
					show:true,
					list: [1,1,3]
				},
				methods:{
					handleClick: function(){
						this.show = !this.show;
					}
				}
			})
		</script>
	</body>
</html>
发布了60 篇原创文章 · 获赞 2 · 访问量 2045

猜你喜欢

转载自blog.csdn.net/qq_41423485/article/details/104096014
今日推荐