vue+elementUI项目中,如何让Element UI的Message消息提示每次只弹出一个
1.封装js,命名为message.js,代码如下:/**防止重复点击重复弹出message弹框 */import {Message} from 'element-ui';let messageInstance = null;const resetMessage = (options) => {if(messageInstance) {messageInstance.close()}mess
·
1.封装js,命名为message.js,代码如下:
/**防止重复点击重复弹出message弹框 */
import {Message} from 'element-ui';
let messageInstance = null;
const resetMessage = (options) => {
if(messageInstance) {
messageInstance.close()
}
messageInstance = Message(options)
}
;['error','success','info','warning'].forEach(type => {
resetMessage[type] = options => {
if(typeof options === 'string') {
options = {
message:options
}
}
options.type = type
return resetMessage(options)
}
})
export const message = resetMessage
2.main.js引用message.js
import ElementUI from 'element-ui'
import {message} from './message.js';//引用message要在Vue.use(ElementUI)后面,不然没有效果
vue.prototype.$message = message;
更多推荐
已为社区贡献9条内容
所有评论(0)