let data = { size: 'small' } let methods = { clickHandler() { } } Object.assign(window, data, methods) // 契约数据 const vdom = { vid: 'root', tag: 'div', attrs: { }, children: [{ vid: 'fe5s1f5gegr4', tag: 'el-row', attrs: {}, children: [{ vid: 'qwef5g165hse', tag: 'el-col', attrs: { span: 12 }, children: [{ vid: '526g4h1fg2hj1', tag: 'el-button', attrs: { size: this.size, icon: 'el-icon-plus', type: 'primary' }, on: { click: this.clickHandler }, text: '按钮' }] }] }] } // 契约转vnode const dataToVnode = (createElement, data) => { let children = [] if (data.children && data.children.length) { children = data.children.map(item => dataToVnode(createElement, item)) } else { children = data.text } return createElement(data.tag, { attrs: { ...data.attrs, vid: data.vid }, on: { ...data.on } }, children) } // 生成vnode const vnode = { render(createElement) { return dataToVnode(createElement, vdom) } } new Vue({ render: h => h(vnode) }).$mount('#app')