vue-global-modal v1.0.4-beta
vue-global-modal
The vue global modal based on global emitter of npm package vue-happy-bus.
Why This?
Easy to use Just a few steps, no complicated setup required.
Only logic & No style Focus on implementing the logic of components, no any default styles.
Usage
First Step
Define your modal and put into vue-global-modal:
<!-- ExampleModal.vue -->
<template>
<GlobalModal name="test" v-slot="{ onConfirm, onCancel }">
<button class="btn-confirm" @click="onConfirm">OK</button>
<button class="btn-cancel" @click="onCancel">Cancel</button>
</GlobalModal>
</template>
<script setup>
import GlobalModal from "vue-plugin-modal";
</script>Second Step
import and call $emit anywhere you need:
<script setup>
import { $emit } from "vue-plugin-modal";
const emitFromApp = () => {
$emit("Alert", {
onConfirm: () => {
console.log("data saved!!");
},
});
};
</script>
<template>
<div>
...
<div>
<!-- something deep in the components -->
<button @click="emitFromApp">emit!</button>
</div>
...
</div>
</template>
Properties
name
type:
Stringdefault:"globalModal"description: Event name for emit.classOnShow
type:
Stringdefault:""description: class names apply when modal showed.classOnHide
type:
Stringdefault:""description: class names apply when modal hided.styleOnShow
type:
Objectdefault:{}description: styles apply when modal showed.styleOnShow
type:
Objectdefault:{}description: styles apply when modal hided.showLogs
type:
Booleandefault:falsedescription: Whether to display the console log when the event is triggered.
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago