EditableCell.vue
871 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<template>
<div class="editable-cell noneFour">
<div v-if="editable" class="editable-cell-input-wrapper">
<a-input :value="value" @change="handleChange" @pressEnter="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>
</template>
<script>
export default {
name: 'EditableCell',
props: ['text'],
data () {
return {
value: this.text,
editable: false,
};
},
methods: {
handleChange (e) {
const value = e.target.value;
this.value = value;
},
check () {
this.editable = false;
this.$emit('change', this.value);
},
edit () {
this.editable = true;
},
},
}
</script>