el-message 默认挂载全局可以使用如下方法调用
<script setup lang="ts">
import { ElMessage } from 'element-plus';
ElMessage(options | string);
ElMessage.success(options | string);
// or
import { getCurrentInstance } form 'vue';
const { proxy } = getCurrentInstance()!;
proxy.$message.success(options | string)
<script>
修改全局 options 以关闭时间为例:duration;
//main.js or app.use(ElementPlus) 文件;
const duration = 6000;
app.config.globalProperties.$message.error = msg => {
return ElMessage({ message: msg as string, type: 'error', duration });
};
app.config.globalProperties.$message.success = msg => {
return ElMessage({ message: msg as string, type: 'success', duration });
};
app.config.globalProperties.$message.warning = msg => {
return ElMessage({ message: msg as string, type: 'warning', duration });
};
app.config.globalProperties.$message.info = msg => {
return ElMessage({ message: msg as string, type: 'info', duration });
};