-
Notifications
You must be signed in to change notification settings - Fork 98
Closed
Description
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
Labels
No labels