vue3.0动态循环icon点击变色,再次点击取消选中

先看效果图
请添加图片描述
点击后发生改变
请添加图片描述
开始上代码
html部分

        <div class="left-circle">
          <div class="whole-circle" ref="wholeCircle"></div>
          <div class="whole-list">
            <ul>
              <li v-for="(item, index) in newArr" :key="index">
                <div
                  class="icon"
                  :class="{ iconactived: spanIndex.indexOf(index) > -1 }"
                  :style="{ background: item.text }"
                  @click="changeCicle(item, index)"
                ></div>
                <span class="name">{{ item.name }}</span>
                <span class="value">{{ item.value }}</span>
                <span class="unit"><span>|</span></span>
                <span class="type">{{ item.type }}</span>
              </li>
            </ul>
          </div>
        </div>

css部分代码

      .left-circle {
        display: flex;
        padding-left: 92px;
        .whole-circle {
          width: 60%;
          height: 100%;
        }
        .whole-list {
          width: 40%;
          height: 100%;
          ul {
            li {
              display: flex;
              align-items: center;
              padding: 20px 10px;
              span {
                margin: 0 10px;
              }
              .icon {
                width: 12px;
                height: 12px;
                border-radius: 50%;
                cursor: pointer;
              }
              .iconactived {
                background: #cccccc !important;
              }
              .name {
                font-size: 22px;
                font-weight: 500;
                color: #3aaeff;
              }
              .value {
                font-size: 38px;
                font-weight: bold;
                color: #ffffff;
              }
              .type {
                color: #00d9ff;
                font-size: 30px;
                font-weight: bold;
              }
              .unit {
                display: flex;
                margin: 0;
                font-size: 22px;
                font-weight: 300;
                color: #ffffff;
                span {
                  opacity: 0.3;
                  margin: 0 2px;
                }
              }
            }
          }
        }
      }

vue3.0JS部分关键代码
关于ref这个响应式引用可以看官网带 ref 的响应式变量

import { ref } from "vue";  //需要引入ref相应变量

  setup() {
    const wholeCircle = ref(null);
    const isactive = ref(0); //选中切换的名字
    const spanIndex = ref([]); //选中icon的数组
    const dataList = [
      { value: 758, name: "付款", type: "30%" },
      { value: 425, name: "接单", type: "20%" },
      { value: 565, name: "发货", type: "10%" },
      { value: 6452, name: "揽收", type: "15%" },
      { value: 4905, name: "签收", type: "6%" },
      { value: 547, name: "撤单", type: "4%" }
    ];
    const color = [
      { text: "#52ca8d" },
      { text: "#06bdf6" },
      { text: "#116fee" },
      { text: "#6e68fd" },
      { text: "#9229fd" },
      { text: "#fdac50" }
    ];
    const newArr = dataList.map((item, index) => {
      return { ...item, ...color[index] };
    });
    let arr = [...newArr];

    const changeCicle = (item, index) => {
      let arrIndex = spanIndex.value.indexOf(index);
      if (arrIndex > -1) {
        spanIndex.value.splice(arrIndex, 1);
        arr.splice(index, 0, item);
      } else {
        spanIndex.value.push(index);
        arr = arr.filter(res => {
          return res.name != item.name;
        });
      }
      
      //let myChart = echarts.init(wholeCircle.value);
      //let bar = orderEcharts.wholeCircle(arr);
      //myChart.setOption(bar);
    };

    return {
      wholeCircle,
      dataList,
      isactive,
      newArr,
      changeCicle,
      spanIndex
    };
  }
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Jet_closer

你的鼓励将是我创作的最大动力

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

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

打赏作者

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

抵扣说明:

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

余额充值