在使用vxe-table組件時,常用的方法就是在columns中使用editRender來引入element-ui的一些組件,但局限性很大,只能使用有限規定的幾個組件,如input, textarea, select, $input, $select, $switch,而使用slots插槽來自定義組件信息則可以使用更多的element-ui組件
1 { 2 3 editRender: {type: 'default'}, 4 slots: { 5 default: ({row}, h) => { 6 return [ 7 h('el-checkbox', { 8 props: { 9 value: row.checkbox 10 } 11 }) 12 ] 13 }, 14 edit: ({row}, h) => { 15 return [ 16 h('el-checkbox', { 17 props: { 18 value: row.checkbox 19 }, 20 on: { 21 change: (value) => { 22 row.checkbox = value; 23 } 24 } 25 }) 26 ] 27 } 28 } 29 }
在默認狀態下和編輯狀態下頁面效果可以保持一致,並且通過edit中的change方法使單選多選框可以獲得編輯功能。
不同的組件獲得的編輯方法不同,如input中獲得編輯的方法為input