Skip to content

请教如何解决这个问题。expected "</>/<=/>=" #81

@Richard-Choooou

Description

@Richard-Choooou

注释掉下面的 jsx 语法可以正常工作。
image

babel.config.js

module.exports = {
    presets: [
        '@vue/app',
        "@babel/preset-typescript",
        "@vue/babel-preset-jsx",
    ],
    plugins: [
        "@babel/plugin-transform-typescript"
    ] 
}

在另一个文件中也使用到了 jsx ,但是没有任何影响。

代码如下:

const createWaringDialog = function(options: {
    title?: string,
    type?: 'danger' | 'primary',
    message?: string,
    render?: (h: CreateElement) => JSX.Element,
    confirmBtnText?: string,
    cancelBtnText?: string
}) {
    options = Object.assign({
        type: 'primary',
        title: '提示',
        confirmBtnText: '确认',
        cancelBtnText: '取消'
    }, options)
    return new Vue<{
        dialogVisible: boolean
    }, {
        open: () => void
        close: () => void
        cancel: () => void
        confirm: () => void
    }>({
        setup: function(props, ctx) {
            const dialogVisible = ref(false)

            function open() {
                dialogVisible.value = true
            }

            function close() {
                ctx.emit('cancel')
                dialogVisible.value = false
            }

            function cancel() {
                ctx.emit('cancel')
                dialogVisible.value = false
            }

            function confirm() {
                ctx.emit('confirm')
                dialogVisible.value = false
            }

            return {
                cancel,
                confirm,
                open,
                close,
                dialogVisible
            }
        },

        render(h) {
            return <dialog-template
                    title={options.title}
                    visible={this.dialogVisible}
                    onClose={this.close}
                    append-to-body={true}
                    destroy-on-close={true}
                    width={"400px"}
                >
                {options.message && <div>{options.message}</div>}
                {options.render && options.render(h)}
                <div slot="footer" style="text-align: center">
                    <el-button size="medium" onClick={this.confirm} type={options.type}>
                        {options.confirmBtnText}
                    </el-button>
                    <el-button size="medium" onClick={this.cancel} plain>{options.cancelBtnText}</el-button>
                </div>
            </dialog-template>
        }
    })
}

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