mini-vue(coderwhy学习笔记)

高峻
2023-12-01
function createApp(rootComponent) {
    return {
        mount(selector) {
            const container = document.querySelector(selector)
            let oldVNode;
            let isMounted = false;

            watchEffect(function() {
                if (!isMounted) {
                    oldVNode = rootComponent.render()
                    mount(oldVNode, container)
                    isMounted = true;
                } else {
                    const newVNode = rootComponent.render()
                    patch(oldVNode, newVNode);
                    oldVNode = newVNode
                }
            })
        }
    }
}

 类似资料: