【问题标题】:Iview UI Table CellIview UI 表格单元格
【发布时间】:2018-10-24 10:20:52
【问题描述】:

当我单击 Vuejs 库 iview 表时,如何访问单元格数据?在更改单元格表 css 之后,我需要单元格表值和列标题。例如,如果我单击一个单元格,它变成红色,在另一个单元格中,它变成绿色

【问题讨论】:

    标签: javascript vue.js iview


    【解决方案1】:
    <template>
        <Table border :columns="columns7" :data="data6"></Table>
    </template>
    <script>
        export default {
            data () {
                return {
                    columns7: [
                        {
                            title: 'Age',
                            key: 'age'
                        },
                        /* blah blah blah...*/
                        {
                            title: 'Action',
                            key: 'action',
                            width: 150,
                            align: 'center',
                            render: (h, params) => {
                                return h('div', [
                                    h('Button', {
                                        props: {
                                            type: 'primary',
                                            size: 'small'
                                        },
                                        style: {
                                            marginRight: '5px'
                                        },
                                        on: {//here you can pass event handlers
                                            click: () => {
                                                this.show(params.index)
                                            }
                                        }
                                    }, 'View'),
                                    h('Button', {
                                        props: {
                                            type: 'error',
                                            size: 'small'
                                        },
                                        on: {
                                            click: () => {
                                                this.remove(params.index)
                                            }
                                        }
                                    }, 'Delete')
                                ]);
                            }
                        }
                    ],
                    data6: [
                        {
                            name: 'John Brown',
                            age: 18,
                            address: 'New York No. 1 Lake Park'
                        },
                        {
                            name: 'Jim Green',
                            age: 24,
                            address: 'London No. 1 Lake Park'
                        },
                        {
                            name: 'Joe Black',
                            age: 30,
                            address: 'Sydney No. 1 Lake Park'
                        },
                        {
                            name: 'Jon Snow',
                            age: 26,
                            address: 'Ottawa No. 2 Lake Park'
                        }
                    ]
                }
            },
            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>
    

    您可以在列定义中提供渲染功能。 (并且在渲染功能中,您可以“绑定”事件接收器)。 jsfiddle,iview doc,Vue - render functions

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-16
      • 2020-08-17
      相关资源
      最近更新 更多