让我们以 vue 2.1.9 为例。
链接:https://cdnjs.cloudflare.com/ajax/libs/vue/2.1.9/vue.js
你们知道哪个函数渲染 DOM 吗?
最佳答案
您始终可以创建渲染
函数。请参阅下面的代码。
Vue.component('anchored-heading', {
render: function (createElement) {
return createElement(
'h' + this.level, // tag name
this.$slots.default // array of children
)
},
props: {
level: {
type: Number,
required: true
}
}
})
这里createElement
是一个函数,如下所示。
// @returns {VNode}
createElement(
// {String | Object | Function}
// An HTML tag name, component options, or function
// returning one of these. Required.
'div',
// {Object}
// A data object corresponding to the attributes
// you would use in a template. Optional.
{
// (see details in the next section below)
},
// {String | Array}
// Children VNodes. Optional.
[
createElement('h1', 'hello world'),
createElement(MyComponent, {
props: {
someProp: 'foo'
}
}),
'bar'
]
)
请参阅this post以获得更多理解。
关于javascript - 哪个函数负责在其渲染引擎中渲染 vue.js 中的 DOM?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41694495/