javascript - 哪个函数负责在其渲染引擎中渲染 vue.js 中的 DOM?

标签 javascript vue.js

让我们以 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/

相关文章:

javascript - .ng-enter 在 Angular 1.3.14 中不起作用?

javascript - 垃圾邮件可以看到/使用 javascript 吗?

Laravel Vue Prop htmlspecialchars()

node.js - 如何离线安装node+vue web程序

javascript - Vue-cli 版本 3 BETA webpack 配置

javascript - 如何在 Vue 中将 API 应用程序 key 作为 prop 传递

javascript - 遍历 ajax 调用返回的每一行

php - Google map 在 JavaScript 弹出窗口中无法正确显示

javascript - jQuery 动画数字计数器从零到值 - 当值达到数十万时计数器显示错误值

laravel 和 vuejs - 您是否正确注册了组件?对于递归组件,请确保提供 "name"选项。在发现