.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>
uni-vue写的小程序多选反选demo
于 2022-06-29 21:28:01 首次发布
这篇博客展示了如何使用Vue.js和TypeScript创建一个多级选择组件,包括全选功能。组件中包含了一个全选的checkbox以及一组可选的checkboxes,通过`van-checkbox`和`van-checkbox-group`实现交互逻辑。在`onChange`和`radioChange`方法中处理选中状态的同步,并用Less进行样式定义。

被折叠的 条评论
为什么被折叠?



