ant或者elment的单选按钮和复选框设置只读

react + ant

<div className='look-box'>
  <Radio.Group defaultValue={data?.answer}>
      <Space direction="vertical">
          {data.contentList.map((dd,index)=> (
              <Radio value={dd.id?dd.id:index}>{dd.text}</Radio>
           ))}
      </Space>
  </Radio.Group>
</div>

inde.less文件

.look-box  /deep/ .ant-radio-group{
  pointer-events: none !important;
}
.look-box /deep/ .ant-checkbox-group{
  pointer-events: none !important;
}

vue + element

<div class="look-box">
  <el-radio-group v-model="currentAnswer" @change="onChange">
    <el-radio :label="dd.id" v-for="dd in item.contentList" :key="dd.id">
       {{dd.text}}   
     </el-radio>
  </el-radio-group>
   <el-checkbox-group v-model="currentAnswer" @change="onChange" >
      <el-checkbox :label="dd.id" v-for="dd in item.contentList" :key="dd.id">
          {{dd.text}}
      </el-checkbox>
   </el-checkbox-group>
</div>

样式

<style scoped lang='less'>
.look-box /deep/ .el-radio{
  display: block;
  pointer-events: none;
  margin:10px 0;
  width: 100%;
  height: auto !important;
}
.look-box /deep/ .el-checkbox{
  display: block;
  margin:10px 0;
  pointer-events: none;
  width: 100%;
  height: auto !important;
}
.look-box /deep/ .el-checkbox__label{
  display: initial;
}
</style>

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,您想了解如何在 ant design vue2 表格中添加复选框。 您可以使用 ant design vue2 的 `<a-checkbox>` 和 `<a-table>` 组件来实现复选框的功能。以下是一个示例代码,其中包含一个带有复选框的表格: ```html <template> <div> <a-table :columns="columns" :data-source="data"> <template slot="selection" slot-scope="{ selectedRowKeys, onChange }"> <a-checkbox-group :value="selectedRowKeys" @change="onChange"> <a-checkbox :value="row.key" v-for="row in data" :key="row.key">{{ row.name }}</a-checkbox> </a-checkbox-group> </template> </a-table> </div> </template> <script> export default { data() { return { columns: [ { title: 'Name', dataIndex: 'name', key: 'name', }, { title: 'Age', dataIndex: 'age', key: 'age', }, { title: 'Address', dataIndex: 'address', key: 'address', }, ], data: [ { key: '1', name: 'John Brown', age: 32, address: 'New York No. 1 Lake Park', }, { key: '2', name: 'Jim Green', age: 42, address: 'London No. 1 Lake Park', }, { key: '3', name: 'Joe Black', age: 32, address: 'Sidney No. 1 Lake Park', }, { key: '4', name: 'Jim Red', age: 32, address: 'London No. 2 Lake Park', }, ], }; }, }; </script> ``` 在上面的代码中,我们使用了 `<a-checkbox>` 和 `<a-table>` 组件来实现复选框的功能。我们在表格中添加了一个名为 `selection` 的插槽,用于展示复选框。然后在插槽中,我们使用 `<a-checkbox-group>` 组件来包含所有的复选框,使用 `<a-checkbox>` 组件来渲染每一行的复选框。我们还需要使用 `slot-scope` 属性来获取已选中的行和更改已选中行的事件。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值