image.pngimage.png
image.pngimage.png

Rendering

Vue2中的render function

  1. render(h) {
  2. return h('div', {
  3. attrs: {
  4. id: 'foo'
  5. },
  6. on: {
  7. click: this.onClick
  8. }, 'hello')
  9. }

Vue3中的render function

  1. <!--
  2. Vue 3 API
  3. * Flat props structure
  4. * Globally imported `h` helper
  5. -->
  6. import { h } from 'vue'
  7. render() {
  8. return h('div', {
  9. id: 'foo',
  10. onClick: this.onClick
  11. }, 'hello')
  12. }

:::info 对于h函数中第二个参数所传递的扁平化对象中,Vue会check这个key 是否已经作为属性存在于原生DOM节点中的(比如上面例子中的id)。如果存在,那么会设置为property, 如果不存在,就设置为一个attribute :::