在项目中使用elementUI
的MessageBox.confirm()
出现了默认不聚焦的问题,默认确认按钮是浅色的,需要点击一下才会变成正常。面对这种问题,创建新组件,实现聚焦。替换默认的MessageBox.confirm()
- 解决
- 创建
components/MessageBoxConfirmWrapper/index.js
import { MessageBox } from 'element-ui'
export default (...args) => {
setTimeout(() => {
document.activeElement?.blur()
}, 0)
return MessageBox.confirm(...args)
}
- 使用
import MessageBoxConfirmWrapper from '@/components/MessageBoxConfirmWrapper'
MessageBoxConfirmWrapper('确定要退出当前账号?', '退出确认', {
type: 'warning'
})
.then(() => {})
.catch(() => {})