iview中table表格组件里的操作按钮显示隐藏

1.table中的操作按钮根据后台的传值来渲染显示不同的按钮?
在这里插入图片描述
2.在vue中,通过使用 render函数来动态渲染html
在style属性中添加一个display属性,然后用三目运算判断后台传入的状态值来控制不同按钮的显示隐藏

<template>
    <Table border :columns="columns7" :data="data6"></Table>
</template>
<script>
    export default {
        data () {
            return {
                columns7: [
                    {
                        title: 'Name',
                        key: 'name',
                        render: (h, params) => {
                            return h('div', [
                                h('Icon', {
                                    props: {
                                        type: 'person'
                                    }
                                }),
                                h('strong', params.row.name)
                            ]);
                        }
                    },
                    {
                        title: 'Age',
                        key: 'age'
                    },
                    {
                        title: 'Address',
                        key: 'address'
                    },
                    {
                        title: 'Action',
                        key: 'action',
                        width: 150,
                        align: 'center',
                        render: (h, params) => {
                            return h('div', [
                                h('Button', {
                                    props: {
                                        type: 'primary',
                                        size: 'small'
                                    },
                                    style: {
                                        marginRight: '5px',
                                       display:(params.row.status=='1') ? "inline-block":"none"
                                    },
                                    on: {
                                        click: () => {
                                            this.show(params.index)
                                        }
                                    }
                                }, '查看'),
                                h('Button', {
                                    props: {
                                        type: 'error',
                                        size: 'small'
                                    },
                                    on: {
                                        click: () => {
                                            this.remove(params.index)
                                        }
                                    }
                                }, '删除')
                            ]);
                        }
                    }
                ],
                data6: [
                    {
                        name: 'John Brown',
                        age: 18,
                        address: 'New York No. 1 Lake Park',
                        status: '1'
                    },
                    {
                        name: 'Jim Green',
                        age: 24,
                        address: 'London No. 1 Lake Park',
                        status: '0'
                    },
                ]
            }
        },
        methods: {
            show (index) {
                this.$Modal.info({
                    title: 'User Info',
                    content: `Name:${this.data6[index].name}<br>Age:${this.data6[index].age}<br>Address:${this.data6[index].address}`
                })
            },
            remove (index) {
                this.data6.splice(index, 1);
            }
        }
    }
</script>

结果:
在这里插入图片描述

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你可以通过以下步骤来删除 Vue + iView 表格的某一行数据: 1. 在表格添加一个“删除”列,并在该列添加一个“删除”按钮,例如,可以使用如下代码: ```html <template> <Table :columns="columns" :data="tableData"> <template slot="operations" slot-scope="{row}"> <Button type="error" @click="deleteRow(row)">删除</Button> </template> </Table> </template> <script> export default { data() { return { columns: [ { title: '姓名', key: 'name' }, { title: '年龄', key: 'age' }, { title: '性别', key: 'gender' }, { title: '操作', slot: 'operations', align: 'center' }, ], tableData: [ { name: '张三', age: 18, gender: '男' }, { name: '李四', age: 20, gender: '女' }, { name: '王五', age: 22, gender: '男' }, ], }; }, methods: { deleteRow(row) { const index = this.tableData.indexOf(row); this.tableData.splice(index, 1); }, }, }; </script> ``` 在上面的代码,我们在表格添加了一个名为“operations”的插槽,该插槽对应了一个“删除”按钮,当用户点击该按钮时,会触发 `deleteRow()` 方法,该方法会从表格数据源删除指定的行。 2. 最后,如果你想要删除某一行数据时,弹出一个确认框,让用户确认是否删除,可以使用 iView 的 `Modal` 对话框组件,例如,可以使用如下代码: ```html <template> <Table :columns="columns" :data="tableData"> <template slot="operations" slot-scope="{row}"> <Button type="error" @click="showDeleteConfirm(row)">删除</Button> </template> </Table> </template> <script> import { Modal } from 'iview'; export default { data() { return { columns: [ { title: '姓名', key: 'name' }, { title: '年龄', key: 'age' }, { title: '性别', key: 'gender' }, { title: '操作', slot: 'operations', align: 'center' }, ], tableData: [ { name: '张三', age: 18, gender: '男' }, { name: '李四', age: 20, gender: '女' }, { name: '王五', age: 22, gender: '男' }, ], }; }, methods: { showDeleteConfirm(row) { Modal.confirm({ title: '确认删除', content: `是否删除 ${row.name}?`, onOk: () => { const index = this.tableData.indexOf(row); this.tableData.splice(index, 1); }, }); }, }, }; </script> ``` 在上面的代码,我们使用了 iView 的 `Modal` 对话框组件,当用户点击“删除”按钮时,会弹出一个确认框,让用户确认是否删除该行数据。如果用户点击“确定”按钮,则会从表格数据源删除该行数据。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值