1. 新增message.js
/*
* @Author : wyatt
* @Date : 2021-08-11 19:30:38
* @LastEditors : wyatt
* @LastEditTime : 2021-08-11 19:38:30
* @Description : 重置element ui message樣式
*/
/**防止重復(fù)點(diǎn)擊重復(fù)彈出message彈框 */
import { Message } from "element-ui";
//定義一個(gè)新的Message方法,多傳入一個(gè)offset參數(shù)
const resetMessage = (options) => {
return Message({
...options,
offset: 60,
});
};
//重寫(xiě)一遍success的方法,將offset寫(xiě)入options
["success", "warning", "info", "error"].forEach((type) => {
resetMessage[type] = (options) => {
if (typeof options === "string") {
options = {
message: options,
offset: 200,
};
}
options.type = type;
return Message(options);
};
});
export const message = resetMessage;
2. main.js中引入
// element-ui 全局配置Message距離窗口頂部的偏移量(offset)
import { message } from "./utils/message.js";
Vue.prototype.$message = message;