Iview Table组件中各种组件扩展的使用

一、Iview Table 组件 多选框选中和禁选设置

Table添加多选框

通过给 columns 数据设置一项,指定  type: 'selection' ,即可自动开启多选功能。

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

  • @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 可以默认选中当前项。

给 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 // 设置复选框选中状态

}

}

二、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

//"未用"

以上是 Iview Table组件中各种组件扩展的使用 的全部内容, 来源链接: utcz.com/z/357863.html

回到顶部