index.ts 536 B

1234567891011121314151617181920212223
  1. import { ElMessage } from 'element-plus'
  2. let messageInstance: any | null = null
  3. const resetMessage = (options: any) => {
  4. if (messageInstance) {
  5. messageInstance.close()
  6. }
  7. messageInstance = ElMessage(options)
  8. }
  9. ['error', 'success', 'info', 'warning'].forEach((type: string) => {
  10. resetMessage[type] = (options: any) => {
  11. if (typeof options === 'string') {
  12. options = {
  13. message: options
  14. }
  15. }
  16. options.type = type
  17. return resetMessage(options)
  18. }
  19. })
  20. export const Message = resetMessage as any