效果(放在ant-design的table里了):
调用:
text是显示的文本
onChange回调函数接受的val是更改后的值
<EditableCell
text={text}
onChange={val => this.onCellChange(record, val)}
/>
export default {
template: `
<div class='editable-cell'>
<div v-if='editable' class='editable-cell-input-wrapper'>
<a-input :value='value' @change='handleChange' @pressEnter='check' @blur='check' />
<a-icon
type='check'
class='editable-cell-icon-check'
@click='check'
/>
</div>
<div v-else class='editable-cell-text-wrapper'>
{{ value || ' ' }}
<a-icon type='edit' class='editable-cell-icon' @click='edit' />
</div>
</div>
`,
props: {
text: String
},
data() {
return {
value: this.text,
editable: false
};
},
methods: {
handleChange(e) {
const value = e.target.value;
this.value = value;
},
check() {
this.editable = false;
console.log('change ok');
console.log(this.value);
this.$emit('change', this.value);
},
edit() {
this.editable = true;
}
}
};