iview表格render多元素封装

<Table :columns="htitle" :data="data"></Table>
 {
                    title: '操作',
                    key: 'operation',
                    render: (h, params) => {
                        const btnList = [
                            {
                                text: "编辑",
                                cb: this.handleEdit.bind(vm, params)
                            },
                            {
                                text: "上移",
                                cb: this.handleToTop.bind(vm, params)
                            },
                            {
                                text: "下移",
                                cb: this.handleToBottom.bind(vm, params)
                            },
                            {
                                text: "删除",
                                cb: this.handleDelete.bind(vm, params)
                            }
                        ];

                        const childrens = btnList.map(btn => {
                            return h(
                                "span",
                                {
                                // props: { type: "text", size: "small"},
                                style: {
                                    marginRight: "5px",
                                    color: "#2d8cf0",
                                    cursor:"pointer"
                                },
                                on: { click: btn.cb }
                                },
                                btn.text
                            );
                        });
                        console.log("childrens",childrens);
                        return h("div", childrens);
                    }
                }

效果:

猜你喜欢

转载自www.cnblogs.com/ivan5277/p/12964692.html