iview怎么通过点击事件来删除选中的表数据

2022-04-13 综合 194阅读

可以使用table的render方法,通过在column中定义一个按钮来实现点击获取选中的数据


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) => { //params是你选中行的数据
                                h('Button', {
                                    props: {
                                        type: 'error',
                                        size: 'small'
                                    },
                                    on: { //使用监听方法监听click事件,实现删除当前行
                                        click: () => {   
                                         this.remove(params.index)
                                        }
                                    }
                                }, 'Delete')
                            ]);
                        }
                    }
                ],
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com