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

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

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

export default (...args) => {
	setTimeout(() => {
		document.activeElement?.blur()
	}, 0)
	return MessageBox.confirm(...args)
}
  1. 使用
import MessageBoxConfirmWrapper from '@/components/MessageBoxConfirmWrapper'
MessageBoxConfirmWrapper('确定要退出当前账号?', '退出确认', { 
	type: 'warning'
 	})
	.then(() => {})
	.catch(() => {})

你可能感兴趣的:(#,elemen-plus,elementui,前端,javascript)