跳到主要内容

ew-message

NPM version npm npm GitHub stars GitHub stars

一个基于 typescript 而封装的消息提示框插件。

安装与使用​

安装​

npm install ew-message
# 或者
yarn add ew-message

@ew-color-picker/utils 是 peer 依赖,npm 7+ / pnpm 8+ 会自动安装,无需额外处理。

引入​

import ewMessage from 'ew-message';
// 样式需要显式引入
import 'ew-message/style.css';

也支持 CDN(UMD 产物已内联 @ew-color-picker/utils,单个文件即可使用,兼容历史用法):

<link rel="stylesheet" href="https://www.unpkg.com/ew-message/dist/ew-message.min.css" />
<script src="https://www.unpkg.com/ew-message/dist/ew-message.min.js"></script>

如果页面里已经引入过 @ew-color-picker/utils,可以改用精简版 ew-message.external.min.js(不再重复打包),需先加载其 UMD 脚本(全局变量 Utils):

<script src="https://www.unpkg.com/@ew-color-picker/utils/dist/utils.min.js"></script>
<script src="https://www.unpkg.com/ew-message/dist/ew-message.external.min.js"></script>

基础用法​

const msg1 = ewMessage('默认消息提示框');
const msg2 = ewMessage({
content: '默认消息提示框',
type: 'success'
});
// 快捷方法
ewMessage.success('操作成功');
ewMessage.error({ content: '操作失败', position: 'top-right' });

配置项​

interface ewMessageOption {
content?: string | Node;
center?: boolean;
type?: 'info' | 'success' | 'warning' | 'error' | 'loading';
duration?: number;
showClose?: boolean;
showTypeIcon?: boolean;
typeIcon?: string;
closeIcon?: string;
container?: string | HTMLElement;
removeClassName?: string[];
startClassName?: string[];
top?: number | string;
html?: boolean;
position?: 'top' | 'top-left' | 'top-right' | 'bottom' | 'bottom-left' | 'bottom-right';
offset?: number | string;
gap?: number;
maxCount?: number;
zIndex?: number;
maxDuration?: number;
clickToClose?: boolean;
pauseOnHover?: boolean;
prefix?: string;
onShow?: (info: { type: string; content: string | Node }) => void;
onClose?: (info: {
type: string;
content: string | Node;
reason: 'timeout' | 'manual' | 'destroy' | 'maxCount';
}) => void;
}

完整的字段说明请参考参数接口。

更新日志​

详情可参考更新日志。