ant 多选框默认不选中

本文探讨Ant Design中的多选框组件,详细解析如何设置默认为未选中状态,涵盖部分选中、全部选中及未选中三种全选状态的实现方法。
摘要由CSDN通过智能技术生成

ant 的多选框 全选状态分三种,部分选中 全部选中 未选中

 <Checkbox
              v-model:checked="state.checkAll"
              :indeterminate="state.indeterminate"
              @change="onCheckAllChange"
            >
              全选此页
            </Checkbox>

state.indeterminate=false
state
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
你可以在 `columns` 中设置 `defaultChecked` 属性来设置默认选中的状态,例如: ```vue <template> <a-table :columns="columns" :data-source="dataSource"></a-table> </template> <script> export default { data() { return { dataSource: [ { key: 1, name: 'John', age: 32, }, { key: 2, name: 'Mike', age: 25, }, { key: 3, name: 'Lucy', age: 28, }, ], columns: [ { title: 'Name', dataIndex: 'name', }, { title: 'Age', dataIndex: 'age', }, { title: 'Selected', dataIndex: 'selected', defaultChecked: true, // 默认选中 scopedSlots: { customRender: 'selected' }, }, ], }; }, }; </script> ``` 在上面的示例中,我们将 `Selected` 列的 `defaultChecked` 属性设置为 `true`,因此默认情况下所有复选框都会被选中。如果你需要根据数据动态设置复选框的选中状态,可以在数据源中为每一行数据添加一个 `selected` 属性,并将其设置为 `true` 或 `false`。然后,在 `Selected` 列的 `scopedSlots` 中使用 `selected` 插槽来渲染复选框,并将 `checked` 属性设置为 `selected` 的值,例如: ```vue <template> <a-table :columns="columns" :data-source="dataSource"></a-table> </template> <script> export default { data() { return { dataSource: [ { key: 1, name: 'John', age: 32, selected: true, }, { key: 2, name: 'Mike', age: 25, selected: false, }, { key: 3, name: 'Lucy', age: 28, selected: true, }, ], columns: [ { title: 'Name', dataIndex: 'name', }, { title: 'Age', dataIndex: 'age', }, { title: 'Selected', dataIndex: 'selected', scopedSlots: { customRender: 'selected', }, }, ], }; }, }; </script> <template #selected="{ text, record }"> <a-checkbox :checked="record.selected"></a-checkbox> </template> ``` 在上面的示例中,我们在数据源中为每一行数据添加了一个 `selected` 属性,并将其设置为 `true` 或 `false`。然后,在 `Selected` 列的 `scopedSlots` 中使用 `selected` 插槽来渲染复选框,并将 `checked` 属性设置为 `selected` 的值,这样就可以根据数据动态设置复选框的选中状态了。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值