首页 > 其他 > 详细

vue标签

时间:2021-04-15 15:15:51      阅读:21      评论:0      收藏:0      [点我收藏+]

Table 中,默认复选框选中,以及禁用操作

            <!-- 表格信息 -->
            <a-table
                :columns="columns"
                :data-source="data"
                :row-selection="{
                    selectedRowKeys: selectedRowKeys,
                    onChange: onSelectChange,
                    getCheckboxProps: getCheckboxProps,
                }"
            >
            </a-table>
  • rowSelection:行选择属性,设置行相关操作
  • selectedRowKeys:一个数组集合,[],用于存放选中的key
  • onChange:点击行时触发的事件
  • getCheckboxProps:设置复选框相关操作的属性
    methods: {
        onSelectChange(selectedRowKeys, selectedRows) { // 选中事件,selectedRows:选中行数据
            this.selectedRowKeys = selectedRowKeys;
            this.selectedRows = selectedRows;
        },
        getCheckboxProps(record) {  // 该方法便利每一行,设置每行的属性
            return {
                props: {
                    disabled: true,  // 设置禁用
                    name: record.appName,  // 设置name属性
                    defaultChecked: true,  // 设置默认选中
                }
            }
        },
    },

官方给出的配置

<a-table :row-selection="rowSelection" :columns="columns" :data-source="data">
    <a slot="name" slot-scope="text">{{ text }}</a>
</a-table>
  computed: {
    rowSelection() {
      return {
        onChange: (selectedRowKeys, selectedRows) => {
          console.log(`selectedRowKeys: ${selectedRowKeys}`, ‘selectedRows: ‘, selectedRows);
        },
        getCheckboxProps: record => ({
          props: {
            disabled: record.name === ‘Disabled User‘, // Column configuration not to be checked
            name: record.name,
          },
        }),
      };
    },
  },

vue标签

原文:https://www.cnblogs.com/shanlaotou/p/14661497.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!