页面:
<script setup>
import { messageModal } from './tipsModal.jsx'
</script>
<template>
<div class="home">
<button
@click="
messageModal('test内容', {
cancel: () => {
console.log('cancel')
},
confirm: () => {
console.log('confirm')
}
})
"
>
弹窗
</button>
</div>
</template>
<style lang="less" scoped></style>
模板:
import { render } from 'vue'
export function messageModal(cur, handle) {
const div = document.createElement('div')
const pro = (
<div>
<div>{cur}</div>
<div
onClick={() => {
document.body.removeChild(div),
console.log('cancel'),
handle.cancel && handle.cancel()
}}
>
取消
</div>
<div
onClick={() => {
document.body.removeChild(div),
console.log('confirm'),
handle.confirm && handle.confirm()
}}
>
同意
</div>
</div>
)
render(pro, div)
document.body.appendChild(div)
}