关于Antd 表格(Table)中插入图片

HTML

<a-table
	:columns="columns"
    :data-source="data"
    :pagination="false"
    :stripe="true">
	//表头
	<span slot="ranktitle" style="color: rgb(245,172,139);">排名</span>
	//表单
	<span slot="img" slot-scope="img">
		//注意此处src需要用动态  :src
	    <img :src="img" width="10px" height="10px">
	</span>
</a-table>

Javascript

import icon1 from "../assets/1.png";
const columns = [
  {
    // title: "排名",
    dataIndex: "rank",
    key: "rank",
    width: 60,
    //表头
    slots: { title: "ranktitle" },
    //插入图片
    scopedSlots: { customRender: "img" }
  }
]

const data = [
  {
    key: "1",
    //图片位置  注意!此处图片需要引入。
    rank: icon1,
  }
]
要使用 Ant Design Vue 的表格树组件,您需要先安装和导入 Table 和 TreeSelect 组件。 在表格,您需要使用 `customExpandIcon` 属性来自定义展开/折叠图标,并使用 `customRow` 属性来自定义行的渲染。 以下是一个示例代码: ```vue <template> <a-table :columns="columns" :data-source="data" :custom-row="customRow" :custom-expand-icon="customExpandIcon"> <template slot="name" slot-scope="{ record }"> {{ record.name }} </template> </a-table> </template> <script> import { Table, TreeSelect } from 'ant-design-vue'; export default { components: { Table, TreeSelect, }, data() { return { columns: [ { title: 'Name', dataIndex: 'name', key: 'name', scopedSlots: { customRender: 'name' }, }, { title: 'Age', dataIndex: 'age', key: 'age', }, { title: 'Address', dataIndex: 'address', key: 'address', }, ], data: [ { key: '1', name: 'Parent 1', age: 30, address: 'New York No. 1 Lake Park', children: [ { key: '1-1', name: 'Child 1-1', age: 12, address: 'New York No. 2 Lake Park', }, { key: '1-2', name: 'Child 1-2', age: 13, address: 'New York No. 3 Lake Park', }, ], }, { key: '2', name: 'Parent 2', age: 32, address: 'London No. 1 Lake Park', children: [ { key: '2-1', name: 'Child 2-1', age: 11, address: 'London No. 2 Lake Park', }, { key: '2-2', name: 'Child 2-2', age: 16, address: 'London No. 3 Lake Park', }, ], }, ], }; }, methods: { customExpandIcon({ record, onExpand }) { if (record.children) { return ( <a onClick={onExpand}> {record._expanded ? <a-icon type="minus-square" /> : <a-icon type="plus-square" />} </a> ); } return null; }, customRow(record, index, indent, expanded) { return { class: `custom-row-${record.key}`, on: { click: () => { console.log(record); }, }, }; }, }, }; </script> ``` 在上面的代码,您可以看到我们自定义了展开/折叠图标和行的渲染,以及使用了插槽 `scopedSlots` 来渲染名称列。您还可以根据您的需求来添加其他自定义的组件或插槽。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值