element-ui,使用message防止多次提示,全局配置可关闭提示
element
A Vue.js 2.0 UI Toolkit for Web
项目地址:https://gitcode.com/gh_mirrors/eleme/element
·
情景:在我们使用message的时候每次操作成功,或者进行一些数据交互的时候会进行message提示,但是假如出现我们操作完成要异步继续进行其他操作,或者多次调用接口时这个时候一直提示对用户是很不友好的,我们只需要让他提示最后一次即可;
1:在untils文件夹下创建 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全局进行注册(一定要放在element引入之后去覆盖掉)
即 Vue.use(Element)之后
Vue.use(Element, {
size: Cookies.get('size') || 'medium'
});
import oneMessage from './utils/oneMessage';
Element.Dialog.props.lockScroll.default = false; // 打开弹窗防止页面抖动
Vue.prototype.$message = oneMessage;
3:在 .vue文件即可正常使用
this.$message.error('您不能审核自己的出入金');
!!!注意:
全局也在使用message去全局拦截提示等操作,也要修改
import oneMessage from '../utils/oneMessage';
oneMessage({
message: res.message||'操作成功',
type: 'error',
duration: 5 * 1000
});
结束~~
A Vue.js 2.0 UI Toolkit for Web
最近提交(Master分支:2 个月前 )
c345bb45
1 年前
a07f3a59
* Update transition.md
* Update table.md
* Update transition.md
* Update table.md
* Update transition.md
* Update table.md
* Update table.md
* Update transition.md
* Update popover.md 1 年前
新一代开源开发者平台 GitCode,通过集成代码托管服务、代码仓库以及可信赖的开源组件库,让开发者可以在云端进行代码托管和开发。旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。
更多推荐


所有评论(0)