iview使用render函数在列表页生成状态列表并修改

只贴出核心代码

截图如下,点击下拉菜单即可修改项目发布状态,显示的内容根据字段status来判断,status为0时未发布,为1时已发布

说明:handleEditStatus方法中只是修改状态,不影响前台显示

columns: [{
            title: '项目状态',
            key: 'status',
            minWidth: 80,
            align: 'center',
            render: (h, params) => {
              let butType, butName
              switch (params.row.status) {
                case 0:
                  butType = 'warning'
                  butName = '未发布'
                  break
                case 1:
                  butType = 'primary'
                  butName = '已发布'
                  break
                default:
                  butType = 'warning'
                  butName = '未发布'
              }
              return h('div', [
                h('Poptip', {
                  id: 'but_poptip',
                  class: 'but_poptip',
                  props: {
                    placement: 'bottom',
                    width: '85px'
                  }
                }, [
                  h('Button', {
                    props: {
                      type: butType,
                      size: 'small'
                    },
                    style: {
                      marginRight: '5px'
                    }
                  }, butName),
                  h('div', {
                    class: 'api',
                    slot: 'content'
                  }, [
                    h('ButtonGroup', {
                        props: {
                          vertical: true,
                          size: 'small'
                        }
                      },
                      [
                        h('Button', {
                          props: {
                            type: 'warning'
                          },
                          on: {
                            click: () => this.handleEditStatus(params.row, 0)
                          }
                        }, '未发布'),
                        h('Button', {
                          props: {
                            type: 'primary'
                          },
                          on: {
                            click: () => this.handleEditStatus(params.row, 1)
                          }
                        }, '已发布')
                      ])
                  ])
                ])
              ])
            }
          }

methods:{
    // 修改发布状态
      handleEditStatus(val, status) {
        debugger
        // 其他逻辑部分。。。
      },
}

<style lang="less">
  .but_poptip .ivu-poptip-popper{
    min-width: 80px!important;
  }
</style>

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值