<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>vue</title>
<script src="vue.js"></script>
</head>
<body>
<!-- vue中的v-if,v-show,v-for
v-if:
v-show:display:none/block
v-for:
-->
<div id="root">
<div v-if="show">hello dog</div>
<button @click="handleClick">toggle</button>
<ul>
<li v-for="(item, index) of list" :key="index">{{item}}</li>
</ul>
</div>
<script>
new Vue({
el:"#root",
data:{
show: true,
list: [1,2,3]
},
methods: {
handleClick: function() {
this.show = !this.show
}
}
})
</script>
</body>
</html>
原文地址:https://www.cnblogs.com/twodoge/p/10230143.html
时间: 2024-11-08 08:03:42