溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Iview Table組件中各種組件擴展的使用

發(fā)布時間:2020-10-22 19:38:05 來源:腳本之家 閱讀:272 作者:崔小真 欄目:web開發(fā)

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

Table添加多選框

通過給 columns 數(shù)據(jù)設置一項,指定  type: 'selection' ,即可自動開啟多選功能。

正確使用好以下事件,可以達到需要的效果:

  • @on-select ,選中某一項觸發(fā),返回值為  selection  和  row ,分別為已選項和剛選擇的項。
  • @on-select-all ,點擊全選時觸發(fā),返回值為  selection ,已選項。
  • @on-selection-change ,只要選中項發(fā)生變化時就會觸發(fā),返回值為  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 可以默認選中當前項。

給 data 項設置特殊 key _disabled: true 可以禁止選擇當前項。

例如:

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 // 設置復選框選中狀態(tài)
 }
}

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

1.圖標禁用方式

{
 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.圖標禁用方式

{
 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)
     }
    }
   })
  ])
 }
},

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

var state = null;

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

//display_state
//"未用"

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持億速云。

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI