What is h
from h => h(App)
render: h => h(App)
是以下形式的简写:
render: function (createElement) {
return createElement(App);
}
where h
是简写createElement
争论;将模板编译成 VNode 的函数
https://github.com/vuejs-templates/webpack-simple/issues/29#issuecomment-312902539 https://github.com/vuejs-templates/webpack-simple/issues/29#issuecomment-312902539
是什么类型的h
的返回值?
Since h
is the createElement
功能,h
这里返回一个VNode
https://v2.vuejs.org/v2/guide/render-function.html#createElement-Arguments https://v2.vuejs.org/v2/guide/render-function.html#createElement-Arguments
模板是否总是编译为 VNode 或返回的函数
一个虚拟节点
您可以执行任一操作,具体取决于您的实现。如果你使用Vue.compile
,然后你可以将模板编译成渲染函数:
var res = Vue.compile('<div><span>{{ msg }}</span></div>')
new Vue({
data: {
msg: 'hello'
},
render: res.render,
staticRenderFns: res.staticRenderFns
})
https://v2.vuejs.org/v2/api/#Vue-compile https://v2.vuejs.org/v2/api/#Vue-compile
如果您使用createElement
函数,然后将模板直接编译成VNode。