vue + iview Table表头中插入图片

6 篇文章 0 订阅

vue + iview Table表头中插入图片


开发中遇到一个问题,在表头中需要插入一个公式,不想再引入别的插件所以考虑用图片代替

正常代码中这样引入图片前端可以正常显示:

 <img style="width: 100px"  src="../../../assets/report.png">

但是在iview 组件的Table表头中插入图片,官方文档没有给出相应的示例,考虑使用renderHeader 函数渲染头部,参考:https://blog.csdn.net/single_cong/article/details/81807834于是有了下面的代码,但是图片死活出不来

columns: [
                {
                    type: 'index',
                    align: 'center',
                    title: '序号',
                    key: 'id',
                    fixed: 'left',
                    width: 65,
                },  {
                    slot: 'scoreChange',
                    minWidth: 200,
                    renderHeader: (h) => h('div', [
                        h('span', '哈哈哈哈哈哈'),
                        h('img', {
                            attrs: {
                                src: '../../../assets/report.png'
                            },
                            style: {
                                width: '100px'
                            }
                        })
                    ])
                }, {
                    title: 'action',
                    align: 'center',
                    slot: 'action',
                    width: 150,
                    fixed: 'right'
                }
            ],

于是继续百度发现https://blog.csdn.net/qq_41115965/article/details/80796211修改后完美显示:

{
                    slot: 'scoreChange',
                    minWidth: 200,
                    renderHeader: (h) => h('div', [
                        h('span', '哈哈哈哈哈哈'),
                        h('img', {
                            attrs: {
                                src: require('../../../assets/report.png')
                            },
                            style: {
                                width: '100px'
                            }
                        })
                    ])
                }

成功后截图:
在这里插入图片描述

事后想想这应该是一个前端最基本的操作,却捣鼓了一天;终究还是自己前端会的太少,需要续断的学习和积累才是硬道理。记录一下自己,以便自己以后复习,写的不好还请多多指教

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值