<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<style>
* {
margin: 0;
padding: 0;
}
.box {
margin-top: 200px;
width: 70px;
height: 170px;
/* background-color: red; */
}
.parent {
position: relative;
width: 100%;
height: 50px;
margin-bottom: 10px;
background-color: pink;
}
.child {
width: 60px;
height: 80px;
position: absolute;
margin-bottom: 10px;
border: 1px solid #000;
left: 75px;
top: 0;
display: none;
/* background-color: red; */
}
span {
display: inline-block;
background-color: green;
}
.current {
display: block;
}
</style>
</head>
<body>
<div id="app">
<div class="box">
<div class="parent" v-for='(parent,index) in list' :key='parent.id' @click='clickparent(index)'>
{{parent.parent}}
<div class="child" :class='clickindex === index ? "current" : ""'>
<a href="" @clck='clear'>x</a>
<span v-for='(child,index) in parent.child' Key='index'>
{{child.children}}
</span>
</div>
</div>
</div>
</div>
<script>
var vm = new Vue({
el: '#app',
data() {
return {
clickindex: '',
list: [
{
id: 1,
parent: '测量',
child: [
{
id: 11,
children: '空间'
},
{
id: 12,
children: '空间'
}
]
},
{
id: 2,
parent: '加油',
child: [
{
id: 22,
children: '手机'
},
{
id: 23,
children: '面子'
}
]
},
{
id: 1,
parent: '操作',
child: [
{
id: 131,
children: '全图'
},
{
id: 121,
children: '清除'
}
]
}
]
}
},
methods: {
clickparent(i) {
console.log(i)
this.clickindex = i
console.log(this.clickindex)
},
clear() {
this.clickindex = ''
}
},
})
</script>
</body>
</html>