在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/Python  網(wǎng)絡(luò)安全  HTML/ vue組件iview中message實現(xiàn)不太理解

vue組件iview中message實現(xiàn)不太理解

問題

在看iview源碼中message的實現(xiàn),不是很理解沒處下手,有大牛能疏導(dǎo)一下嗎?

如:

this.$Message.success('This is a success tip');

這個的實現(xiàn)過程

iview官網(wǎng)
iview github

回答
編輯回答
過客

你不理解哪塊?

整體實現(xiàn)是有一個v-for所有notice類的組件。你每調(diào)用一次就往里push一個。


1.success->message

// 幾種方法最終都是調(diào)用message
success (options) {
    return this.message('success', options);
}

2.message-->notice

message(type, options){
        if (typeof options === 'string') {
            options = {
                content: options
            };
        }
        return notice(options.content, options.duration, type, options.onClose, options.closable);
    }

3.noitice-->getMessageInstance

function notice (content = '', duration = defaults.duration, type, onClose = function () {}, closable = false) {
    //...
    // 這個應(yīng)該是拿實例
    let instance = getMessageInstance()
    // 這個應(yīng)該是真正append到頁面上
    instance.notice({
        
    });

    // 用于手動消除,返回值不用管
    return (function () {
    })();
}

4.getMessageInstance-->Notification.newInstance

function getMessageInstance () {
    // 復(fù)用?
    messageInstance = messageInstance || Notification.newInstance({
    });
    return messageInstance;
}

5.iview/src/components/base/notification/index.js

Notification.newInstance = properties => {
    const _props = properties || {};
    // 創(chuàng)建了一個統(tǒng)一v-for所有notice類的組件
    const Instance = new Vue({
        data: _props,
        render (h) {
            return h(Notification, {
                props: _props
            });
        }
    });

    const component = Instance.$mount();
    document.body.appendChild(component.$el);
    return {
        // 3里有調(diào)用notice()的一步
        notice (noticeProps) {
            // 調(diào)了組件的add,向v-for隊列里加了一個,去notification.vue能看到
            notification.add(noticeProps);
        }
    };
2017年4月15日 00:57