@tetap/overlays-vue2
v0.4.4
Published
> overlays only supports Vue3 | Vue2 Composition-api
Downloads
2
Readme
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 Vue from 'vue'
import unoverlay from '@overlays/vue'
const app = new Vue({})
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>
import { useOverlay } from '@overlays/vue2'
export default {
mixins: [useOverlay({ duration: 1000 })],
methods: {
onClick() {
// use this.$visible
// use this.$resolve or this.$reject
}
}
}
</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"