项目场景:
谷歌浏览器
问题描述
谷歌浏览器 el-dialog 概率出现背景全黑,透明度不生效
class v-modal opacity:0.5 不生效
解决方案:
采用 opacity: 1 background: 0.5透明度的黑色
代码如下:
import Vue from 'vue'
import Element from 'element-ui'
import '../element-variables.scss'
/**
* 来自 Karen 的帅气注释 2022-06-13 11:22:55
* 解决遮罩层黑屏
*/
const resetModalStyle = () => {
setTimeout(() => {
const vmodal = document.body.getElementsByClassName('v-modal')
if (vmodal.length) {
vmodal[0].style.opacity = 1
vmodal[0].style.background = 'rgba(0,0,0,0.5)'
}
})
}
const dialogWatch = Element.Dialog.watch.visible
Element.Dialog.watch.visible = function() {
return new Promise(resolve => {
resetModalStyle()
resolve(dialogWatch.apply(this, arguments))
})
}
const MessageConfirm = Element.MessageBox.confirm
Element.MessageBox.confirm = function() {
return new Promise(resolve => {
resetModalStyle()
resolve(MessageConfirm.apply(this, arguments))
})
}
Vue.use(Element)
End