Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
vue-modal-core
Advanced tools
一个轻量级的 Vue 3 模态框管理库,提供灵活的模态框控制和生命周期管理。
npm install vue-modal-core
# 或
yarn add vue-modal-core
# 或
pnpm add vue-modal-core
MyModal.vue
):<template>
<div v-if="visible" class="modal">
<div class="modal-content">
<!-- 你的模态框内容 -->
<button @click="$emit('update:visible', false)">关闭</button>
</div>
</div>
</template>
<script setup lang="ts">
defineProps<{
visible: boolean
}>()
</script>
import { createModalContext } from 'vue-modal-core'
import MyModal from './MyModal.vue'
// 创建模态框上下文
const { makeModal, ModalRenderer } = createModalContext({
baseZIndex: 1000, // 基础 z-index
allowMultiple: true, // 是否允许多个模态框同时存在
debug: false // 是否开启调试日志
})
// 创建模态框实例
const modal = makeModal(MyModal)
// 打开模态框
modal.open({
// 传入 props(除了 visible)
title: '标题',
content: '内容'
})
// 关闭模态框
await modal.close()
// 检查模态框是否可见
const isVisible = modal.isVisible()
<template>
<div>
<!-- 你的应用内容 -->
<modal-renderer />
</div>
</template>
你可以使用 onBeforeClose
钩子来控制模态框的关闭行为:
import { onBeforeClose } from 'vue-modal-core'
// 在模态框组件中
onBeforeClose(async () => {
// 返回 false 可以阻止模态框关闭
const shouldClose = await askUser()
return shouldClose
})
// 创建多个模态框实例
const modal1 = makeModal(MyModal, Symbol('Modal1'))
const modal2 = makeModal(MyModal, Symbol('Modal2'))
// 控制是否允许多个模态框同时显示
const { makeModal, ModalRenderer } = createModalContext({
allowMultiple: false // 设置为 false 时会自动关闭之前的模态框
})
库提供完整的 TypeScript 类型支持,可以获得完整的类型提示:
import type { ExtractComponentOptions } from 'vue-modal-core'
// 模态框的 props 类型会自动推导
const modal = makeModal(MyModal)
modal.open({
// 这里会获得完整的类型提示
})
参数 | 类型 | 默认值 | 说明 |
---|---|---|---|
baseZIndex | number | 1000 | 模态框基础 z-index 值 |
allowMultiple | boolean | true | 是否允许多个模态框同时存在 |
debug | boolean | false | 是否开启调试日志 |
方法 | 参数 | 返回值 | 说明 |
---|---|---|---|
open | props: ExtractComponentOptions | void | 打开模态框 |
close | - | Promise | 关闭模态框 |
isVisible | - | boolean | 获取模态框可见状态 |
visible
prop 和 update:visible
事件onBeforeClose
钩子必须在组件的 setup 函数或 <script setup>
中使用onBeforeClose
钩子会按照后进先出(LIFO)的顺序执行创建模态框上下文,返回模态框管理器实例。
interface ModalOptions {
baseZIndex?: number; // 基础 z-index 值
enableAnimation?: boolean; // 是否启用动画
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 模态框管理库,提供灵活的模态框控制和生命周期管理
The npm package vue-modal-core receives a total of 0 weekly downloads. As such, vue-modal-core popularity was classified as not popular.
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
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.