Skip to content

Using jsx in el-table-column's formatter function #194

@youthug

Description

@youthug

Hi there.
I defined a variable: columns in column-config.js :

const columns = [
    {
        label: 'First Name',
        prop: 'firstName',
        defaultShow: true,
        minWidth: '180px',
        // TODO return el-tag
        formatter(row, column, cellValue) {
            return (
                <el-tag>{ cellValue }</el-tag>
            )
        }
    },
    {
        label: 'Last Name',
        prop: 'lastName',
        defaultShow: true,
        minWidth: '180px'
    }
]

export {
    columns
}

And use it in App.vue:

<template>
    <div id="app">
        <el-table :data="tableData">
            <!-- bind all attrs -->
            <el-table-column v-for="(col, i) in columns" :key="i" v-bind="col"/>
        </el-table>
    </div>
</template>

<script>
import { columns } from "@/config/column-config";

...

Then I got errors in console: TypeError: h is not a function
image

Here is my code: jsx-demo

Is there any way to return templates in .js files outside render and data function?

Thx.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions