react中怎么动态显示colunm

columnsFilter = (mobile) => {
        let columns
        // 16619924200
        // 15242099188
        if (['15242099188'].includes(mobile)) {
            columns = [
                {
                    title: '商品名称',
                    dataIndex: 'productName',
                    key: 'productName',
                },
                {
                    title: '条码',
                    dataIndex: 'barCode',
                    key: 'barCode',
                },
                {
                    title: '型号',
                    dataIndex: 'type',
                    key: 'type',
                },
                {
                    title: '品牌',
                    dataIndex: 'brandName',
                    key: 'brandName',
                },
                {
                    title: '单位',
                    dataIndex: 'unitOne',
                    key: 'unitOne',
                },
                {
                    title: '数量',
                    dataIndex: 'quantity',
                    key: 'quantity',
                },
                {
                    title: '操作',
                    dataIndex: 'operation',
                    key: 'operation',
                    // [' 15242099188'].includes(this.state.mobile) ? 
                    render: (text, item) => (
                        <>
                            {
                                // console.log(this.state.mobile, 'this.state.mobile')
                                // ['15242099188'].includes(this.state.mobile) ? 
                                <a className="delBtn" onClick={() => this.handleDelArchives(item)} >删除</a>
                            }
                        </>
                    )
                },
            ]
        } else {
            columns = [
                {
                    title: '商品名称',
                    dataIndex: 'productName',
                    key: 'productName',
                },
                {
                    title: '条码',
                    dataIndex: 'barCode',
                    key: 'barCode',
                },
                {
                    title: '型号',
                    dataIndex: 'type',
                    key: 'type',
                },
                {
                    title: '品牌',
                    dataIndex: 'brandName',
                    key: 'brandName',
                },
                {
                    title: '单位',
                    dataIndex: 'unitOne',
                    key: 'unitOne',
                },
                {
                    title: '数量',
                    dataIndex: 'quantity',
                    key: 'quantity',
                }

            ]
        }
        return columns
    }

 <Table
                                rowKey="id"
                                columns={this.columnsFilter(mobile)}
                                dataSource={getDetail ? getDetail.goodsList : []}
                                bordered
                                pagination={false}
                                rowSelection={rowSelection}
                            />

你可能感兴趣的:(react.js,javascript,前端)