iview Table组件渲染操做按钮, render 渲染icon图标更改方法

问题描述: Table组件操做,iview自带的icon并不能知足个人须要,根据render函数的属性,本身写了几种方式,后续会继续添加html


1, 使用iview自带的icon图标bash

这个不方便改变他们的icon类型,使用受到局限
复制代码
let products: any = {
      columns: [{
        title: '操做',
        key: 'Action',
        width: 150,
        render: (h, params) => {
          return h('div', [
            h('Icon', {
              props: {
                type: 'trash-a' // iview自带的删除icon
              },
              style: {
                fontSize: '18px', // 改变icon的样式
                color: '#559DF9'
              },
              on: {
                click: () => {
                    console.log(111) // 点击操做事件
                }
              }
            })
          ])
        }
      }
    }
复制代码

2, 在render函数里面添加innerhtmliview

新建span标签,在span里面添加i标签,生成本身想要的icon
复制代码
let products: any = {
      columns: [{
        title: '操做',
        key: 'Action',
        width: 150,
        render: (h, params) => {
          return h('div', [
              h('span', {
                style: {
                  fontSize: '18px',
                  color: '#559DF9'
                },
                domProps: { // 添加标签,使用本身引入的iconfont图标
                  innerHTML: "<i class='icon iconfont'>&#xe64f;</i>"
                },
                on: {
                  click: () => {
                    console.log(111) // 点击操做事件
                  }
                }
              })
          ])
        }
      }
    }
复制代码

3, 改变render 类名来生成想要的图标dom

直接新建i标签,增长class名称,和innerhtml

个人iconfont引入方式是Unicode格式的,若是是 font class格式的会更简单,只须要改变class名称就能够了
复制代码
let products: any = {
      columns: [{
        title: '操做',
        key: 'Action',
        width: 150,
        render: (h, params) => {
          return h('div', [
              h('i', {
              class: 'icon iconfont',
               style: {
                fontSize: '18px',
                color: '#559DF9'
              },
              domProps: {
                innerHTML: '&#xe64f;' // iconfont图标
              },
              on: {
                click: () => {
                  console.log(111) // 点击操做事件
                }
              }
            })
          ])
        }
      }
    }
复制代码
相关文章
相关标签/搜索