ant vue中给table列自定义样式

效果图

在这里插入图片描述

代码
columns: [
	{ title: '序号', dataIndex: 'index', align: 'center', width: '5%', scopedSlots: { customRender: 'index' } },
	{
		title: '版本名称',
		dataIndex: 'versionName',
		align: 'center',
		ellipsis: true,
		customCell: (record) => {
			//条件成立才显示自定义样式
			if(record.isDefault){
				return {
					style: {
						backgroundImage: "url(" + require("@/assets/icons/default.svg") + ")",
						backgroundRepeat: "no-repeat",
						backgroundSize: "30%",
						backgroundPosition: '105% -7px',
					}
				}
			}
		},
	},
	{ title: '版本号', dataIndex: 'versionNo', align: 'center' , ellipsis: true },
],
vue3写法
columns.splice(1, 0, {
    title: typeName.value + '单编号', dataIndex: 'formNo', align: 'center', width: '160px',
    customCell: (record) => {
      if(record.formLevel === '2'){
        return {
          style: {
            backgroundImage: "url("+ _this.$myUtil.getAssetsFile('icons', 'urgent.svg') + ")",
            backgroundRepeat: "no-repeat",
            backgroundSize: "25%",
            backgroundPosition: '100%',
          }
        }
      }
    },
  });

 /**
  * 获取assets目录下的文件
  * @param url
  * @param fileName
  * @returns {string}
  */
 getAssetsFile(url, fileName) {
     return new URL(`../assets/${url}/${fileName}`, import.meta.url).href;
 },

差别不大,只是 require 在 vite + vue3 中不支持,改成使用 new URL() 获取地址
更新于2024-01-25

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值