npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

vue-modal-core

v1.0.8

Published

一个轻量级的 Vue 3 模态框管理库,提供灵活的模态框控制和生命周期管理

Readme

vue-modal-core

一个轻量级且灵活的 Vue 3 模态框组件库,为您的 Vue 应用提供更好的模态框管理方案。

npm version license

特性

  • 🎯 完全基于 TypeScript 开发,提供完整的类型支持
  • 🚀 轻量级设计,无外部依赖
  • 💪 支持异步关闭控制
  • 🎨 灵活的自定义样式
  • 📦 支持多模态框管理
  • 🔧 简单易用的 API

安装

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
});
  1. 创建模态框组件:
<!-- 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>
  1. 在应用中使用:
import { makeModal } from './dialog';
import MyModal from './MyModal.vue';

// 创建模态框上下文


// 创建模态框实例
const modal = makeModal(MyModal);

// 打开模态框
modal.open({
  // 传入 props
  content: 'Hello, World!'
});

setTimeout(() => {
  modal.close();
}, 3000);

  1. 在应用根组件中挂载渲染器:
<!-- App.vue -->
<script setup lang="ts">
import { ModalRenderer } from './dialog';
</script>
<template>
  <Teleport to="body">
    <ModalRenderer />
  </Teleport>
  <!-- Page Content -->
</template>

API 文档

createModalContext

创建模态框上下文,返回模态框管理器实例。

interface ModalOptions {
  baseZIndex?: number;      // 基础 z-index 值
  allowMultiple?: boolean;   // 是否允许多个模态框同时存在
  debug?: boolean;          // 是否启用调试模式
}

const context = createModalContext(options?: ModalOptions);

makeModal

创建模态框实例。

const modal = makeModal(YourModalComponent);

// 返回的实例包含以下方法:
interface ModalInstance {
  open: (props: ComponentProps) => void;  // 打开模态框
  close: () => Promise<boolean>;          // 关闭模态框
  isVisible: () => boolean;               // 获取模态框可见状态
}

onBeforeClose

添加模态框关闭前的钩子函数。

onBeforeClose(() => {
  // 返回 false 可以阻止模态框关闭
  return true;
});

其它

  • 这个项目基本是我自己一个人在使用的,所以可能会有一些问题,欢迎提交 PR 和 Issue

许可证

MIT