UNPKG

956 BJavaScriptView Raw
1// @flow
2import type { CONSTRUCTOR_OPTION } from './type'
3import getProps from './props'
4import getMethods from './methods'
5import getContainerStyle from './style'
6// 生成vue render方法
7export default function (option: CONSTRUCTOR_OPTION): Function {
8 const components = option.component
9
10 function render (vueInstance, h, components, option) {
11 if (option) {
12 const { prop, method } = option
13 return h(components, {
14 props: getProps(vueInstance, prop),
15 on: getMethods(vueInstance, method)
16 }) // 若存在组件配置
17 } else return h(components) // 不存在组件配置
18 }
19
20 return function (h: Function) {
21 const vueInstance = this // this指向vue实例
22 return Array.isArray(components) ?
23 h('div', getContainerStyle(option.style), components.map(({ components, option }) => render(vueInstance, h, components, option)))
24 : render(vueInstance, h, components.components, components.option)
25 }
26}
\No newline at end of file