vue3-watermark-plugin
Version:
A powerful Vue 3 watermark plugin with component and directive support
44 lines (36 loc) • 1.03 kB
JavaScript
/**
* Vue3 Watermark Plugin
* 支持组件和指令两种使用方式的水印插件
*/
import WatermarkComponent from './Watermark/index.vue';
import { watermarkDirective } from './directives/index.js';
// 插件安装函数
const install = (app, options = {}) => {
// 注册水印组件
app.component('Watermark', WatermarkComponent);
// 注册水印指令
app.directive('watermark', watermarkDirective);
// 全局配置
if (options.globalConfig) {
app.config.globalProperties.$watermarkConfig = options.globalConfig;
}
};
// 插件对象
const WatermarkPlugin = {
install,
WatermarkComponent,
watermarkDirective
};
// 默认导出插件对象,支持 app.use()
export default WatermarkPlugin;
// 单独导出组件和指令,支持按需引入
export {
WatermarkComponent,
WatermarkComponent as Watermark,
watermarkDirective,
install
};
// 自动安装(如果在浏览器环境中通过 script 标签引入)
if (typeof window !== 'undefined' && window.Vue) {
install(window.Vue);
}