1. 程式人生 > >vue 實現購物清單實現二級選單

vue 實現購物清單實現二級選單

<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>實現二級選單Vue</title>
<script src="vue.min.js"></script>
<style>

</style>
</head>
<body>
<div id="my">
<ul>
<li v-for="item in lists">
<a @click="show(item)">{{item.name}}</a>
<ul v-show="item.isShow">
<li v-for="sub in item.sub">
{{sub.name}}
</li>
</ul>
</li>
</ul>
</div>

<script>
window.onload=function(){
new Vue({
el:'#my',
data:{
lists:[
{
name:'流行',
isShow:false,
sub:[{name:'就'},{name:'是'}]
},
{
name:'流行1',
isShow:true,
sub:[{name:'就1'},{name:'是1'}]
}
]
},
methods:{

show:function(v){
this.lists.forEach(function(item){
item.isShow=false;
});
v.isShow=!v.isShow
}
}
})
}

</script>
</body>
</html>