选项卡

<!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>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值