elementUI中MessageBox.confirm()默认不聚焦问题处理

在项目中使用elementUIMessageBox.confirm()出现了默认不聚焦的问题,默认确认按钮是浅色的,需要点击一下才会变成正常。面对这种问题,创建新组件,实现聚焦。替换默认的MessageBox.confirm()

  • 解决
  1. 创建components/MessageBoxConfirmWrapper/index.js
js 复制代码
import { MessageBox } from 'element-ui'

export default (...args) => {
	setTimeout(() => {
		document.activeElement?.blur()
	}, 0)
	return MessageBox.confirm(...args)
}
  1. 使用
js 复制代码
import MessageBoxConfirmWrapper from '@/components/MessageBoxConfirmWrapper'
MessageBoxConfirmWrapper('确定要退出当前账号?', '退出确认', { 
	type: 'warning'
 	})
	.then(() => {})
	.catch(() => {})
相关推荐
JarvanMo1 分钟前
深度解析:如何彻底终结 Flutter 异步操作中的 BuildContext 崩溃?
前端
wxr06166 分钟前
部署Spring Boot项目+mysql并允许前端本地访问
前端·spring boot·mysql·持续部署
假装我不帅12 分钟前
jquery-validation使用
前端·javascript·jquery
怕浪猫17 分钟前
React从入门到出门第六章 事件代理机制与原生事件协同
前端·javascript·react.js
天府之绝21 分钟前
uniapp 中使用uview表单验证时,自定义扩展的表单,在改变时无法触发表单验证处理;
开发语言·前端·javascript·vue.js·uni-app
be or not to be22 分钟前
Html-CSS动画
前端·css·html
初恋叫萱萱27 分钟前
技术基石与职场进阶:构建从Web后端到高性能架构的完整知识图谱
前端·架构·知识图谱
木木木一31 分钟前
Rust学习记录--C9 错误处理
前端·学习·rust
局外人LZ33 分钟前
libsodium.js:web端与 Node.js 的现代加密工具集,构建前端安全加密体系
前端·javascript·node.js
xkxnq38 分钟前
第二阶段:Vue 组件化开发(第 20天)
前端·javascript·vue.js