uni-vue写的小程序多选反选demo

这篇博客展示了如何使用Vue.js和TypeScript创建一个多级选择组件,包括全选功能。组件中包含了一个全选的checkbox以及一组可选的checkboxes,通过`van-checkbox`和`van-checkbox-group`实现交互逻辑。在`onChange`和`radioChange`方法中处理选中状态的同步,并用Less进行样式定义。
.generate(@n, @i: 4) when (@i =< @n) {
<template>
  <div>
    <van-checkbox :value="checked" @change="radioChange">全选</van-checkbox>
    <div class="class-all" v-for="item in list" :key="item.id">
      <div class="discount">
        <div class="discount-content"></div>
        <van-checkbox-group :value="result" @change="onChange">
          <van-checkbox :name="item.id" class="checkBox"></van-checkbox>
        </van-checkbox-group>
      </div>
    </div>
  </div>
</template>
<script lang="ts">
import Vue from 'vue'

export default Vue.extend({
  name: 'Rights',
  data() {
    return {
      checked: false,
      result: ['1'],
      list: []
    }
  },
  methods: {
    onChange(item) {
      this.result = [...item.detail]
      if (!item.detail.length) {
        this.checked = false
      } else if (item.detail.length === this.list.length) {
        this.checked = true
      } else {
        this.checked = false
      }
    },
    radioChange(item) {
      this.checked = item.detail
      if (item.detail) {
        const listAll = this.list.map((item: any) => item.id)
        this.result = [...listAll]
      } else {
        this.result.splice(0, this.result.length)
      }
    }
  },
})
</script>
<style lang="less" scoped>
.class-all {
  .discount {
    width: 100%;
    height: 200px;
    background: red;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .discount-content {
      width: 100px;
      height: 100px;
      background-color: #fff;
    }
  }
}
</style>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值