美文网首页
Ant Design of Vue中table表格选中项的清除问

Ant Design of Vue中table表格选中项的清除问

作者: 喜欢走弯路的人 | 来源:发表于2022-11-09 11:42 被阅读0次

使用 :rowSelection.selectedRowKeys 来控制选项

vue js

为方便大家复制粘贴,这里直接上代码

<template>

  <div>

    <div style="margin-bottom: 16px">

      <a-button type="primary" :loading="loading" @click="clearSelection">

        清空选中项

      </a-button>

    </div>

    <a-table

      :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"

      :columns="columns"

      :data-source="data"

    />

  </div>

</template>

<script>

const columns = [

  {

    title: 'Name',

    dataIndex: 'name',

  },

  {

    title: 'Age',

    dataIndex: 'age',

  },

  {

    title: 'Address',

    dataIndex: 'address',

  },

];

const data = [];

for (let i = 0; i < 46; i++) {

  data.push({

    key: i,

    name: `Edward King ${i}`,

    age: 32,

    address: `London, Park Lane no. ${i}`,

  });

}

export default {

  data() {

    return {

      data,

      columns,

      selectedRowKeys: [],

      selectedRows:[],

      loading: false,

    };

  },

  methods: {

    clearSelection() {//清空选中项

      this.loading = true;

      setTimeout(() => {

        this.loading = false;

        this.selectedRowKeys = [];

        this.selectedRows = []

      }, 1000);

    },

    onSelectChange(selectedRowKeys,selectedRows) {

      console.log('selectedRowKeys changed: ', selectedRowKeys);

      this.selectedRowKeys = selectedRowKeys; //选中的keys

      this.selectedRows = selectedRows //选中的行

    },

  },

};

</script>

相关文章

网友评论

      本文标题:Ant Design of Vue中table表格选中项的清除问

      本文链接:https://www.haomeiwen.com/subject/csnotdtx.html