Iview Table組件中各類組件擴展

1、Iview Table 組件 多選框選中和禁選設置ios

Table添加多選框this

經過給 columns 數據設置一項,指定 type: 'selection',便可自動開啓多選功能。spa

正確使用好如下事件,能夠達到須要的效果:code

  • @on-select,選中某一項觸發,返回值爲 selection 和 row,分別爲已選項和剛選擇的項。
  • @on-select-all,點擊全選時觸發,返回值爲 selection,已選項。
  • @on-selection-change,只要選中項發生變化時就會觸發,返回值爲 selection,已選項。
<template>
  <div>
    <Table ref="selection" :columns="columns" :data="data" @on-selection-change="selectChange"></Table>
  </div>
</template>

<script>
  export default {
        data () {
          return {
          columns: [ { type: 'selection', width: 60, align: 'center' }, { title: 'Name', key: 'name' }]
        }
      },
      methods: {
        selectChange: function (data) {
          console.log(data[i].name)
        }
      }
</script>

給 data 項設置特殊 key _checked: true 能夠默認選中當前項。blog

給 data 項設置特殊 key _disabled: true 能夠禁止選擇當前項。事件

例如:ip

for (var i = 0; i < res.data.list.length; i++) {
  if (res.data.list[i].status === '1') {
    res.data.list[i]._disabled = true // 設置複選框禁用
    res.data.list[i]._checked= true // 設置複選框選中狀態
  }
}

2、Iview Table 組件中點擊Icon彈出Poptip的寫法ci

1.圖標禁用方式it

{
  title: '撤銷',
  key: 'operate',
  width: 70,
  fixed: 'right',
  render: (h, params) => {
    if (params.row.status === '1') { // 選中當前行信息
      return h('div', [
        h('div', [
          h('Poptip', {
            props: {
              confirm: true,
              title: '肯定要撤銷嗎!'
            },
            on: {
              'on-ok': () => {
                this.cancelFunction(params.index)
              }
            }
          }, [
            h('Button', {
              props: {
                shape: 'circle',
                icon: 'md-return-left'
              }
            })
          ])
        ])
      ])
    } else {
      return h('div', [
        h('Button', {
          props: {
            shape: 'circle',
            icon: 'md-return-left',
            disabled: true // 禁用圖標
          }
        })
      ])
    }
  }
},

2.圖標禁用方式io

{
  title: '修改',
  key: 'operate',
  fixed: 'right',
  width: 70,
  textAlign: 'right',
  render: (h, params) => {
    return h('div', [
      h('Button', {
        props: {
          shape: 'circle',
          icon: 'ios-paper-plane',
          disabled: params.row.status !== '0'
        },
        on: {
          click: () => {
            this.editFunction(params.index)
          }
        }
      })
    ])
  }
},

3、四元運算符 : 多個三元運算符 嵌套

var state = null;

var display_state = (state == null ? "未用" : (state == true ? "在用" : "停用"))

//display_state
//"未用"
相關文章
相關標籤/搜索