vue点击取消再点击选中(单选)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>单选(点击选中,点击取消)</title>
    <script src="https://cdn.bootcss.com/vue/2.5.22/vue.js"></script>
    <style>
        *{
            padding: 0;
            margin: 0;
        }
        .btnBox{
            margin-top: 100px;
        }
        .btn{
            padding: 10px;
            width: 80px;
            height: 40px;
            background: #a8d7e6;
            border-radius: 5px;
            margin-left: 10px;
            cursor: pointer;
            border: 1px solid #ccc;
        }
        .isActive{
            background: pink;
        }
    </style>
</head>
<body>
    <div class="btnBox" >
        <span class="btn" v-for="(item,index) in list" :class="{ isActive:isChange == index}" @click="clickBtn(index)">{{item.name}}</span>
    </div>
</body>
<script>
    var app=new Vue({
        el:'.btnBox',
        data:{
           list:[
                {name:'title1', id:1},
                {name:'title2', id:2},
                {name:'title3', id:3},
            ],
            isChange:-1,
        },
        methods:{
            clickBtn(index){
                if(index!=this.isChange){
                    this.isChange = index;

                }else{
                    this.isChange = -1;

                }
            }
        },
    })
</script>
</html>

在这里插入图片描述

感谢您的支持

  • 9
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

知 秋~

文章里可以看到打赏码哦~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值