关于ant-design-vue:分享一个基于antdesignvue1的表格操作按钮组件
应用成果先看下默认成果 反对按钮超过肯定数量主动放到【更多】下拉按钮外面 按钮反对动态控制是否禁用,是否显示。 上面是一个代码示例。export default Vue.extend({ data() { return { dataSource: [ { id: 1, username: '张三', disabled: 1 }, { id: 2, username: '李四', disabled: 0 }, { id: 3, username: '王二麻子', disabled: 0 }, ] as MyData[], columns: [ // { title: '#', dataIndex: 'id' }, { title: '姓名', dataIndex: 'username' }, { title: '状态', dataIndex: 'disabled', customRender: (value: number) => { return value === 0 ? ( <a-tag color="green">启用</a-tag> ) : ( <a-tag>禁用</a-tag> ); }, }, useActionButtons<MyData>({ align: 'center', title: '操作', limit: 0, showDivider: false, buttons: [ { icon: 'search', text: '查看' }, { icon: 'edit', text: '编辑' }, { text: '禁用', visible: (record) => record.disabled === 0, }, { text: '启用', visible: (record) => record.disabled === 1, }, { icon: 'message', text(record, index) { return `未读音讯(${record.id.toString()})`; }, }, { icon: 'delete', text: '删除', disabled: (record) => record.disabled === 0, click: (record, index) => { this.$confirm({ content: `确认删除${record.username}吗?`, }); }, }, ], }), ], }; },});介绍用法type useActionButtons = (config: ActionButtonsConfig) => Table.Column;原理就是通过一个函数,返回了一个带customRender的列的配置。 ...