必备技能三、render渲染函数

Vue 推荐使用在绝大多数情况下使用 template 来创建你的 HTML。然而在一些场景中,你真的需要 JavaScript 的完全编程的能力,这就是 render 函数,它比 template 更接近编译器。

 

 

 

 

export const TablePlugins = {
  install (Vue, opts) {
    Vue.prototype.getCellRender = (h, cfgs, type = 'Button') => {
      const comps = []
      cfgs.forEach(cfg => {
        cfg.size = cfg.size || 'small'
        cfg.color = cfg.color || 'green'
        cfg.disabled = cfg.disabled || false
        tagProcess(cfg)
        comps.push(h(cfg.tag || type, {
          props: { ...cfg },
          on: cfg.on,
          style: { ...cfg.style },
          'class': { ...cfg.class }
        }, cfg.label, cfg.render))
      })
      return h('div', {
        style: { display: 'inline-block' }
      }, comps)
    }
  }
}

  

posted @ 2019-08-29 09:35  前端王者(法师)  阅读(824)  评论(0编辑  收藏  举报