element-plus消息提示的封装

网编 156 0
import { ElMessage } from "element-plus";
import type { EpPropMergeType } from "element-plus/es/utils/vue/props/types";
/**
 *
 * @param msg 提示的内容
 * @param type 提示的类型
 */
function showToast(
  msg: string,
  type: EpPropMergeType<
    StringConstructor,
    "success" | "warning" | "info" | "error",
    unknown
  >
) {
  ElMessage({
    message: msg,
    type,
  });
}

function success(msg: string) {
  showToast(msg, "success");
}
function warning(msg: string) {
  showToast(msg, "warning");
}
function info(msg: string) {
  showToast(msg, "info");
}
function error(msg: string) {
  showToast(msg, "error");
}

export { showToast, success, warning, info, error };


// 使用
import { success } from "@/utils/element-util"
success("登陆成功!")

标签: #string #info

  • 评论列表

留言评论