Commit 9d9622cde1824f0e6842838ff9117e4f9ea40d1a
1 parent
d497786e
Exists in
master
and in
1 other branch
feat: 优化表格条件渲染
Showing
1 changed file
with
6 additions
and
2 deletions
Show diff stats
packages/table/editor.vue
| ... | ... | @@ -108,6 +108,9 @@ function editorRender(h, context, item) { |
| 108 | 108 | const contentProps = context.props || {}; |
| 109 | 109 | return function(scope) { |
| 110 | 110 | const value = get(scope.row, item.prop); |
| 111 | + if (item.if === false) { | |
| 112 | + return cellRender(h, context, item)(scope); | |
| 113 | + } | |
| 111 | 114 | if (item.if && typeof item.if === 'function') { |
| 112 | 115 | const showEditor = item.if({ item, value, index: scope.$index, ...scope }); |
| 113 | 116 | if (!showEditor) { |
| ... | ... | @@ -118,7 +121,7 @@ function editorRender(h, context, item) { |
| 118 | 121 | // 默认 |
| 119 | 122 | const setValue = val => { |
| 120 | 123 | if (get(contentProps, 'editor.force') === true) { |
| 121 | - vnode.componentInstance.$set(scope.row, item.prop, val); | |
| 124 | + if (vnode.componentInstance) vnode.componentInstance.$set(scope.row, item.prop, val); | |
| 122 | 125 | } else { |
| 123 | 126 | scope.row[item.prop] = val; |
| 124 | 127 | } |
| ... | ... | @@ -136,7 +139,7 @@ function editorRender(h, context, item) { |
| 136 | 139 | const bindProp = path[0]; |
| 137 | 140 | const propValue = cloneDeep(scope.row); |
| 138 | 141 | set(propValue, item.prop, val); |
| 139 | - vnode.componentInstance.$set(scope.row, bindProp, propValue[bindProp]); | |
| 142 | + if (vnode.componentInstance) vnode.componentInstance.$set(scope.row, bindProp, propValue[bindProp]); | |
| 140 | 143 | } else { |
| 141 | 144 | setValue(val); |
| 142 | 145 | } |
| ... | ... | @@ -256,6 +259,7 @@ export default { |
| 256 | 259 | <style lang="scss"> |
| 257 | 260 | .z-table-editor { |
| 258 | 261 | .column-editor { |
| 262 | + padding: 0; | |
| 259 | 263 | .cell { |
| 260 | 264 | padding: 2px; |
| 261 | 265 | .el-form-item { | ... | ... |