vuejs message-box

阅读更多


 

 

export default (Vue) => {
    let MessageBoxConstructor = Vue.extend(require('./message.box.vue'));

    let instance;

    let defaultCallback = (action) => {
        instance.resolve({
            value: instance.vm.inputValue,
            action: action
        });
    };
    let MessageBox = function (options) {
        options = options || {};
        if (typeof options === 'string') {
            options = {
                message: options
            };
        }
        let userOnClose = options.onClose;

        options.onClose = function () {
            MessageBox.close(id, userOnClose);
        };

        instance = new MessageBoxConstructor({
            data: options
        });
        instance.vm = instance.$mount();
        document.body.appendChild(instance.vm.$el);
        instance.vm.visible = true;
        instance.dom = instance.vm.$el;
        return instance.vm;
    };
    ['alert', 'confirm', 'prompt', 'msgbox'].forEach(type => {
        let proxy = '$' + type;
        MessageBox[proxy] = (options) => {
            options.type = type;
            let promise = new Promise(function (resolve, reject) {
                options.resolve = resolve;
                options.reject = reject;
            });
            MessageBox(options);
            return promise;
        };
        Vue.prototype[proxy] = MessageBox[proxy];
    });
    return MessageBoxConstructor;
};

 

你可能感兴趣的:(vuejs message-box)