# vue-directives-kit **Repository Path**: cbTest/vue-directives-kit ## Basic Information - **Project Name**: vue-directives-kit - **Description**: Vue 自定义指令集合,帮助开发者轻松实现常见交互需求,提升开发效率 - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2026-06-18 - **Last Updated**: 2026-06-18 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Vue Directives Kit 一个功能丰富的 Vue 3 自定义指令库,提供实用的指令功能,支持完整的 TypeScript 类型提示和编辑器跳转。 ## ✨ 特性 - 🚀 **Vue 3 原生支持** - 基于 Vue 3 Composition API - 📚 **完整的 TypeScript 支持** - 提供完整的类型定义 - 🔧 **编辑器智能提示** - 支持 VSCode 跳转到定义 - 🎨 **丰富的指令功能** - 提供多种实用指令 - 📱 **响应式设计** - 适配各种屏幕尺寸 - 🔒 **错误处理完善** - 提供详细的错误信息和回调 ## 📦 安装 ```bash npm install vue3-directives-kit # 或 yarn add vue3-directives-kit # 或 pnpm add vue3-directives-kit ``` ## 🚀 快速开始 ### 全局注册 ```typescript import { createApp } from 'vue'; import VueDirectivesKit from 'vue3-directives-kit'; import 'vue3-directives-kit/dist/vue3-directives-kit.css'; // 导入样式 import App from './App.vue'; const app = createApp(App); app.use(VueDirectivesKit); app.mount('#app'); ``` ### 按需引入 ```typescript import { createApp } from 'vue'; import { tooltip, copy, watermark, formatNumber, enter, esc, download } from 'vue3-directives-kit'; import 'vue3-directives-kit/dist/vue3-directives-kit.css'; // 导入样式 import App from './App.vue'; const app = createApp(App); app.directive('tooltip', tooltip); app.directive('copy', copy); app.directive('watermark', watermark); app.directive('formatNumber', formatNumber); app.directive('enter', enter); app.directive('esc', esc); app.directive('download', download); app.mount('#app'); ``` ## 📋 可用指令 ### 1. v-tooltip - 工具提示指令 在元素上显示美观的工具提示。 #### 基础用法 ```vue ``` #### 定位方向 ```vue ``` #### HTML 内容支持 ```vue ``` #### 动态内容 ```vue ``` ### 2. v-copy - 点击复制指令 增强版的点击复制功能,支持多种配置选项。 #### 基础用法 ```vue ``` #### 带回调的用法 ```vue ``` #### 富文本复制 ```vue ``` ### 3. v-watermark - 水印指令 为页面或元素添加水印,保护内容版权。 #### 基础文本水印 ```vue
``` #### 多行水印 ```vue
``` #### 图片水印 ```vue
``` #### 旋转水印 ```vue
``` ### 4. v-format-number - 数字格式化指令 用于格式化数字输入,支持千位分隔符、小数位数限制、负数处理等功能。 #### 基础用法(金额输入) ```vue ``` #### 价格输入(不允许负数) ```vue ``` #### 工资输入(只允许整数) ```vue ``` #### 百分比输入 ```vue ``` ### 5. v-enter - Enter 键监听指令 用于监听元素上的 Enter 键按下事件,特别适合表单提交场景。 #### 登录表单示例 ```vue ``` #### 搜索框示例 ```vue ``` #### 聊天输入框 ```vue ``` ### 6. v-esc - Escape 键监听指令 用于监听元素上的 Escape 键按下事件,特别适合模态框和弹出层。 #### 模态框示例 ```vue ``` #### 搜索框取消 ```vue ``` #### 编辑模式退出 ```vue ``` ### 7. v-download - 文件下载指令 用于触发文件下载操作,支持文本、JSON、CSV等多种格式。 #### 文本文件下载 ```vue ``` #### JSON 文件下载 ```vue ``` #### CSV 文件下载 ```vue ``` #### 简化用法 ```vue ``` #### 自定义数据下载 ```vue ``` ## 🔧 API 参考 ### v-format-number 配置选项 | 参数 | 类型 | 默认值 | 描述 | | ----------------- | -------- | --------- | ------------------ | | decimalPlaces | number | 2 | 小数位数 | | thousandSeparator | boolean | true | 是否添加千位分隔符 | | allowNegative | boolean | true | 是否允许负数 | | maxValue | number | undefined | 最大值限制 | | onFormat | function | undefined | 格式化完成回调 | | onInvalid | function | undefined | 无效输入回调 | ### v-enter / v-esc 回调函数 ```typescript // 回调函数接收 KeyboardEvent 参数 const handleKeyEvent = (event: KeyboardEvent) => { console.log('按键事件:', event); }; ``` ### v-download 配置选项 | 参数 | 类型 | 默认值 | 描述 | | --------- | ----------------------------- | -------------- | -------------- | | data | string \| Blob \| ArrayBuffer | - | 文件内容或数据 | | filename | string | 'download.txt' | 文件名 | | mimeType | string | 'text/plain' | MIME 类型 | | onSuccess | function | undefined | 下载成功回调 | | onError | function | undefined | 下载失败回调 | ## 🎯 演示 项目包含完整的演示页面,展示所有指令的功能和用法。 ### 运行演示 ```bash # 克隆项目 git clone https://gitee.com/Gitfubobo/vue-directives-kit.git # 安装依赖 cd vue-directives-kit npm install # 启动开发服务器 npm run dev ``` 访问 http://localhost:5173 查看演示效果。 ## 🤝 贡献 欢迎提交 Issue 和 Pull Request! ## 📄 许可证 MIT License ## � 联系方式 - 项目地址: [https://gitee.com/Gitfubobo/vue-directives-kit](https://gitee.com/Gitfubobo/vue-directives-kit) - 作者: fubobo