0.4.7 • Published 3 months ago
@overlays/vue v0.4.7
Getting Started
overlays only supports Vue3 | Vue2 Composition-api
Install
With pnpm:
pnpm add @overlays/vue
With yarn:
yarn add @overlays/vue
Global
You can register overlays globally, which will inherit the application context for all popups.
// main.js
import { createApp } from 'vue'
import unoverlay from '@overlays/vue'
const app = createApp({})
app.use(unoverlay)
Usage
Step 1: Define Component
overlays is suitable for most components. Using useOverlay can provide finer control over the component process.
<!-- overlay.vue -->
<script setup>
import { defineEmits, defineProps } from 'vue'
import { useOverlay } from '@overlays/vue'
const props = defineProps({
title: String,
})
// Get Overlay information from useOverlay
const { visible, resolve, reject } = useOverlay({
// Duration of popup layer duration to avoid premature destruction of the component
duration: 1000,
})
</script>
<template>
<div v-if="visible" @click="resolve(`${title}:confirmed`)">
{{ title }}
</div>
</template>
Step 2: Create Overlay
You can use the defineOverlay
method to convert the component into a modal dialog in Javascript / Typescript, which allows you to call it.
import { defineOverlay } from '@overlays/vue'
import OverlayComponent from './overlay.vue'
// Convert to imperative callback
const callback = defineOverlay(OverlayComponent)
// Call the component and get the value of the resolve callback
const value = await callback({ title: 'callbackOverlay' })
// value === "callbackOverlay:confirmed"
You can also use renderOverlay
to directly call the component and skip the defineOverlay
method.
import { renderOverlay } from '@overlays/vue'
import OverlayComponent from './overlay.vue'
const value = await renderOverlay(OverlayComponent, {
title: 'useOverlay'
})
// value === "useOverlay:confirmed"