代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalaable=no">
<title>vueTest</title>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<style type="text/css">
* {
margin: 0px;
padding: 0px;
}
#reddiv{
width: 50px;
height: 50px;
background: red;
}
</style>
</head>
<body>
<div id="app">
{{name}}<br>
<input type="text" v-model="name"><br>
<input type="text" v-model="nameReverse"><br>
{{showDiv}}
<input type="checkbox" v-model="showDiv"><br>
<div v-if="showDiv" id="reddiv"></div>
<hr>
<ul>
<li v-for="item in allIndex">{{item}}</li>
</ul>
</div>
<script type="text/javascript">
var app=new Vue({
el:"#app",
data:{
name:"我的vue.js",
showDiv:true,
persons:[
{index:"A",group:[{name: "A张三"}]},
{index:"B",group:[{name: "B张三"}]},
{index:"C",group:[{name: "C张三"}]},
{index:"D",group:[{name: "D张三"}]}
]
},
computed:{
nameReverse:function (){
var nameArray=this.name.split("");
var reversedNameArray= nameArray.reverse();
var reversedName =reversedNameArray.join("");
return reversedName;
},
allIndex:function (){
var list=[];
for(var i=0 ;i<this.persons.length;i++){
var oneGroup=this.persons[i];
list.push(oneGroup.index);
}
return list;
}
}
});
</script>
</body>
</html>