参考element-plus的notification函数式调用实现
准备自己搞个el-dialog
函数式调用,但是使用vue里面导出的render后,可以成功挂载到body上,但是标签还是el-dialog
,没有解析成div
// Index.vue
<template>
<el-dialog
append-to-body
destroy-on-close
:close-on-click-modal="false"
:close-on-press-escape="false"
:width="dialogWidth"
style="--el-dialog-border-radius: 8px"
class="common-dialog"
>
<slot />
</el-dialog>
</template>
import { VNode, createVNode, ref, render } from 'vue'
import DialogConstructor from './Index.vue'
export const createDialog = (
content: VNode,
options: { show?: boolean } = {}
) => {
const show = ref(options.show ?? true)
const vm = createVNode(
DialogConstructor,
{ modelValue: show.value },
() => content
)
render(vm, document.body)
return {
open: () => (show.value = true),
close: () => (show.value = false)
}
}
// 用法
const dialog = createDialog(
h(Form, {
loading: loading.value,
modelValue: model.value,
onSubmit: () =>
execute(model.value).then(() => {
dialog.close()
emits('refresh')
})
})
)
试过用tsx,也不行