<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script src="./vue.js"></script>
</head>
<body>
<div id="root">
<div v-show="show">123</div>
<div v-if="!show">456</div>
<button @click="change">点击</button> <!-- 点击按钮会出现123/456切换成456/123 -->
<ul>
<li v-for="(item,index) of list":key="index">{{item}}</li> <!-- v-for -->
</ul>
</div>
<script>
new Vue({
el:"#root",
data:{
show:true,
list:[1,2,3]
},
methods:{
change:function(){
this.show=!this.show;
}
}
})
</script>
</body>
</html>
VUE(v-if,v-show,v-for)
最新推荐文章于 2024-02-23 23:27:00 发布