![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
vue-modal-core
Advanced tools
一个轻量级且灵活的 Vue 3 模态框组件库,为您的 Vue 应用提供更好的模态框管理方案。
npm install vue-modal-core
# 或
yarn add vue-modal-core
# 或
pnpm add vue-modal-core
1.创建实例
// dialog.ts
import { createModalContext } from 'vue-modal-core';
export { makeModal, ModalRenderer } = createModalContext({
baseZIndex: 1000,
allowMultiple: true
});
<!-- MyModal.vue -->
<script setup lang="ts">
import { onBeforeClose } from 'vue-modal-core';
defineProps<{
content: string;
}>()
defineModel<boolean>('visible')
// 在模态框组件中使用关闭前钩子
onBeforeClose(async () => {
await new Promise(resolve => setTimeout(resolve, 1000));// 等待 1 秒
// 返回 false 可以阻止模态框关闭
});
</script>
<template>
<div class="modal" :class="{ 'show': visible }">
<div class="modal-content">
{{ content }}
<button @click="$emit('update:visible', false)">关闭</button>
</div>
</div>
</template>
import { makeModal } from './dialog';
import MyModal from './MyModal.vue';
// 创建模态框上下文
// 创建模态框实例
const modal = makeModal(MyModal);
// 打开模态框
modal.open({
// 传入 props
content: 'Hello, World!'
});
setTimeout(() => {
modal.close();
}, 3000);
<!-- App.vue -->
<script setup lang="ts">
import { ModalRenderer } from './dialog';
</script>
<template>
<Teleport to="body">
<ModalRenderer />
</Teleport>
<!-- Page Content -->
</template>
创建模态框上下文,返回模态框管理器实例。
interface ModalOptions {
baseZIndex?: number; // 基础 z-index 值
allowMultiple?: boolean; // 是否允许多个模态框同时存在
debug?: boolean; // 是否启用调试模式
}
const context = createModalContext(options?: ModalOptions);
创建模态框实例。
const modal = makeModal(YourModalComponent);
// 返回的实例包含以下方法:
interface ModalInstance {
open: (props: ComponentProps) => void; // 打开模态框
close: () => Promise<boolean>; // 关闭模态框
isVisible: () => boolean; // 获取模态框可见状态
}
添加模态框关闭前的钩子函数。
onBeforeClose(() => {
// 返回 false 可以阻止模态框关闭
return true;
});
FAQs
一个轻量级的 Vue 3 模态框管理库,提供灵活的模态框控制和生命周期管理
We found that vue-modal-core demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.