Vue中render: h => h(App)的含义

2023-05-25,,

// ES5
(function (h) {
return h(App);
}); // ES6
h => h(App);

官方文档

render: function (createElement) {
return createElement(
'h' + this.level, // tag name 标签名称
this.$slots.default // 子组件中的阵列
)
}

h是Vue.js 里面的 createElement 函数,这个函数的作用就是生成一个 VNode节点,render 函数得到这个 VNode 节点之后,返回给 Vue.js 的 mount 函数,渲染成真实 DOM 节点,并挂载到根节点上。

函数只有一个参数的时候()可以省略;当函数体只有一句话{}可以省略,所以 render: (h) => {h(App)};就变成 render: h => h(App);

等价于components: { App },template: '<App/>'

Vue中render: h => h(App)的含义的相关教程结束。

《Vue中render: h => h(App)的含义.doc》

下载本文的Word格式文档,以方便收藏与打印。