Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
238 views
in Technique[技术] by (71.8m points)

我希望把 elementUI 的MessageBox.alert 自动加一个 callback 选项

我希望把 elementUI 的MessageBox.alert 的option中 自动加一个 callback 选项,里面有写别的操作。
代码使用的时候 像这样子 :MessageBox.alert('获取密码失败')

大家帮我修正一下。 看哪儿出问题了。


官网说明
### 全局方法

如果你完整引入了 Element,它会为 Vue.prototype 添加如下全局方法:$msgbox, $alert, $confirm 和 $prompt。因此在 Vue instance 中可以采用本页面中的方式调用 `MessageBox`。调用参数为:

*   `$alert(message, title, options)` 或 `$alert(message, options)`

我的代码。。:

import { MessageBox } from 'element-ui'

let alert = MessageBox.alert  //beforeClose


MessageBox.alert = function(){

    //$alert(message, title, options) 或 $alert(message, options)

    console.log(arguments)

    var arguments =[].slice.apply(arguments);

    console.log(arguments)

    if(arguments.length==1){

        arguments.push([null,{

            callback :function(){

                document.getElementById('elePowerPass').style.display='block';
            }

        }])

    } else if(arguments.length==2){



        if(arguments[1] && typeof arguments[1]=="object"){

            var callback = arguments[1].callback

            arguments[1].callback = function(){

                document.getElementById('elePowerPass').style.display='block';

                callback&&callback();
            }

        }else{




        }


    }else if(arguments.length==3){

            var callback = arguments[2].callback

            arguments[2].callback = function(){

                document.getElementById('elePowerPass').style.display='block';

                callback&&callback();
            }


    }


    alert.call(this, ...arguments)

}

export { MessageBox }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
import { MessageBox } from 'element-ui'

let alert = MessageBox.alert //beforeClose

MessageBox.alert = function() {

    //element官方文档规定调用方式: $alert(message, title, options) 或 $alert(message, options)

    [...document.querySelectorAll('.powerpass-container')].forEach((ele)=>{
        ele.querySelector('object').style.display='none';
    })

    return alert(...arguments).then(() => { 

        [...document.querySelectorAll('.powerpass-container')].forEach((ele)=>{
            ele.querySelector('object').style.display='block';
        })

        console.log('aaaaaaaaaaaaaaa')  

    }).catch(() => { 

        [...document.querySelectorAll('.powerpass-container')].forEach((ele)=>{
            ele.querySelector('object').style.display='block';
        })
        console.log('bbbbb')
    })

}
export { MessageBox }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
...