情景:在我們使用message的時(shí)候每次操作成功,或者進(jìn)行一些數(shù)據(jù)交互的時(shí)候會(huì)進(jìn)行message提示,但是假如出現(xiàn)我們操作完成要異步繼續(xù)進(jìn)行其他操作,或者多次調(diào)用接口時(shí)這個(gè)時(shí)候一直提示對(duì)用戶是很不友好的,我們只需要讓他提示最后一次即可;
1:在untils文件夾下創(chuàng)建? oneMessage.js,完整代碼如下
import { Message } from 'element-ui';
let messageInstance = null;
const resetMessage = (options) => {
if (messageInstance) {
messageInstance.close();
}
options.showClose = true;
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 default resetMessage;
2:main.js全局進(jìn)行注冊(cè)(一定要放在element引入之后去覆蓋掉)
即 Vue.use(Element)之后
Vue.use(Element, {
size: Cookies.get('size') || 'medium'
});
import oneMessage from './utils/oneMessage';
Element.Dialog.props.lockScroll.default = false; // 打開(kāi)彈窗防止頁(yè)面抖動(dòng)
Vue.prototype.$message = oneMessage;
3:在 .vue文件即可正常使用
this.$message.error('您不能審核自己的出入金');
!??!注意:
全局也在使用message去全局?jǐn)r截提示等操作,也要修改文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-561414.html
import oneMessage from '../utils/oneMessage';
oneMessage({
message: res.message||'操作成功',
type: 'error',
duration: 5 * 1000
});
結(jié)束~~文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-561414.html
到了這里,關(guān)于element-ui,使用message防止多次提示,全局配置可關(guān)閉提示的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!