场景
使用element的时候通常是全局main.js引入,然后每次使用调用不同类型,但是如果你想全局每次调用的时间都缩短。那么就得全局引入的时候重写一下
常规引用
// Vue.prototype.$message = Message
重写
Vue.prototype.$message=function(msg){
msg.type= msg.type=='error' ? 'warning':msg.type;
Message(msg)
}
let messagearr=['success', 'warning','info', 'error']
messagearr.forEach(function (type) {
Vue.prototype.$message[type] = function (options) {
type = type=='error'?'warning' : type;
return Message({
message: options,
type:type,
duration:500,
offset:200
});
}
})