el-message

import { Message } from 'element-ui'
 const showMessage = function (options) {
     let obj={}
    const messageDom = document.getElementsByClassName('el-message')[0]
    if(typeof options!='object'){
        obj.message=options
    }
    if (messageDom === undefined) {
        obj.type=obj.type?obj.type:'warning'
      Message(obj)
    }
 }
const arr = ['success', 'warning', 'info', 'error']
arr.forEach(type => {
  showMessage[type] = options => {
    let obj={}
    if(typeof options!='object'){
        obj.message=options
    }
    const messageDom = document.getElementsByClassName('el-message')[0]

    if (messageDom === undefined) {
        obj.type=obj.type?obj.type:'warning'
      Message[type](obj)
    }
  };
});
export default showMessage;

import ShowMessage from '@/utils/index';
Vue.prototype.$message = ShowMessage;

 this.$message.error('操作成功');
posted @ 2022-04-14 22:51  7c89  阅读(159)  评论(0编辑  收藏  举报