vue中的render函數(shù)應用過程:
API
基于Iview
Button組件
render: (h, params) => {
return h('div', [
h('Button', {
props: {
type: 'success',
size: 'small'
},
style: {
marginRight: '5px'
},
on: {
click: () => {
this.edit(params.index)
}
}
}, '修改'),
h('Button', {
props: {
type: 'error',
size: 'small'
},
style: {
marginRight: '5px'
},
on: {
click: () => {
this.del(params.index)
}
}
}, '刪除')
]);
}, render: (h, params) => {
return h('div', [
h('Button', {
props: {
type: 'success',
size: 'small'
},
style: {
marginRight: '5px'
},
on: {
click: () => {
this.edit(params.index)
}
}
}, '修改'),
h('Button', {
props: {
type: 'error',
size: 'small'
},
style: {
marginRight: '5px'
},
on: {
click: () => {
this.del(params.index)
}
}
}, '刪除')
]);
},
Switch組件
render: (h, params) => {
return h('i-switch', {
props: {
size: 'large',
value: params.row.show === 1
},
scopedSlots: {
open: () => h('span', '開啟'),
close: () => h('span', '關閉')
},
on: {
'on-change': (value) => {
console.log(params.index, value)
}
}
});
},
關于IviewUI框架為什么render函數(shù)按鈕可以用Button,而開關卻是i-switch,我探索了一下Iveiw官網(wǎng),發(fā)下官方解釋如下圖:

12291708-5efab080707c2_articlex.png