vue选项卡

<!DOCTYPE html>
<html lang='en'>

<head>
    <meta charset='UTF-8'>
    <meta http-equiv='X-UA-Compatible' content='IE=edge'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            list-style: none;
        }

        .tab {
            width: 800px;
            height: 40px;
            margin: 10px auto;
        }

        .tab li {
            text-align: center;
            width: 200px;
            line-height: 40px;
            display: inline-block;
        }

        .box {
            width: 800px;
            height: 750px;
            margin: auto;
        }

        .box li {
            width: 800px;
            height: 750px;
            display: none;
        }

        .box li img {
            width: 100%;
            height: 100%;
        }

        .active{
            background-color: pink;
        }

        .tive{
            display: block !important;
        }
    </style>
</head>

<body>
    <div id='myApp'>
        <ul class="tab">
            <li v-for="(time,index) in arr" :key="time.id" :class="[i == index ? 'active' : '' ]" @click="change(index)">{{time.TabControl}}</li>
        </ul>

        <ul class="box">
            <li v-for="(time,index) in arr" :key="time.id" :class="[i == index ? 'tive' : '' ]">
                <img :src="time.url" alt="">
            </li>
        </ul>
    </div>
</body>
<script src='https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js'></script>
<script>
    new Vue({
        el: '#myApp',
        data: {
            i: 0,
            arr: [
                { id: 1, TabControl: '第一个选项', url: 'https://uploadfile.bizhizu.cn/up/ef/df/dd/efdfddb79435265b24aad6714d952724.jpg' },
                { id: 2, TabControl: '第二个选项', url: 'https://www.succedu.com/d/file/2020/07/25/a1c0ca9e51.jpg' },
                { id: 3, TabControl: '第三个选项', url: 'https://img.zmtc.com/2019/0806/20190806060940425.jpg' },
                { id: 4, TabControl: '第四个选项', url: 'https://www.mlito.com/wp-content/uploads/2018/03/bf478dbc95.jpg' }
            ]
        },
        methods: {
            change(index){ // 接收索引值
                this.i = index // 把索引值赋值给i
            }
        },
    })
</script>

</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值