1
This commit is contained in:
parent
07c7dfaa78
commit
c132816a9f
@ -16,7 +16,6 @@ const showMessage = ({ type = 'warning', message, duration = 2000 }) => {
|
||||
visible.value = false
|
||||
}, duration)
|
||||
}
|
||||
|
||||
defineExpose({ showMessage })
|
||||
</script>
|
||||
|
||||
|
44
app/components/x-message/useMessage.js
Normal file
44
app/components/x-message/useMessage.js
Normal file
@ -0,0 +1,44 @@
|
||||
import { createApp, nextTick } from 'vue'
|
||||
import MessagePopup from './index.vue'
|
||||
|
||||
const message = {
|
||||
success(text, duration = 2000) {
|
||||
if (process.client) {
|
||||
this.show({ type: 'success', message: text, duration })
|
||||
}
|
||||
},
|
||||
error(text, duration = 2000) {
|
||||
if (process.client) {
|
||||
this.show({ type: 'error', message: text, duration })
|
||||
}
|
||||
},
|
||||
warning(text, duration = 2000) {
|
||||
if (process.client) {
|
||||
this.show({ type: 'warning', message: text, duration })
|
||||
}
|
||||
},
|
||||
show({ type = 'success', message, duration = 2000 }) {
|
||||
if (!process.client) return
|
||||
|
||||
const container = document.createElement('div')
|
||||
document.body.appendChild(container)
|
||||
|
||||
const app = createApp(MessagePopup, {
|
||||
onAfterLeave: () => {
|
||||
app.unmount()
|
||||
document.body.removeChild(container)
|
||||
}
|
||||
})
|
||||
|
||||
const instance = app.mount(container)
|
||||
nextTick(() => {
|
||||
instance.showMessage?.({
|
||||
type,
|
||||
message,
|
||||
duration
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export { message }
|
@ -1,8 +1,13 @@
|
||||
<template>
|
||||
<main class="flex flex-col min-h-svh">
|
||||
<div class="flex-1 pb-[var(--van-nav-bar-height)]">
|
||||
<AppHeader class="h-[var(--van-nav-bar-height)]" />
|
||||
|
||||
<div class="flex-1 p-16 pb-[var(--van-nav-bar-height)]">
|
||||
<slot />
|
||||
</div>
|
||||
|
||||
<AppFooter />
|
||||
</main>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
</script>
|
Loading…
Reference in New Issue
Block a user