-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEditable.vue
57 lines (49 loc) · 1.06 KB
/
Editable.vue
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<template>
<div>
<div v-show="!editing" @dblclick="setEditing(true)">
<label> {{item}} </label>
</div>
<!-- // @keyup.enter.prevent="setEditing(false)" -->
<textarea v-focus="editing" class="input" v-show="editing" v-model="val" @blur='setEditing(false)'></textarea>
</div>
</template>
<style scoped>
label {
width: 100%;
border: 1px solid transparent;
/* otherwise empty cell click event does not fire */
}
div {
height: 100%;
border: 1px solid transparent;
}
</style>
<script>
import {
focus
} from 'vue-focus';
export default {
data: () => ({
val: '',
editing: false
}),
props: ['item'],
directives: {
focus: focus
},
methods: {
setEditing: function(e) {
this.editing = e;
if (e) {
this.val = this.item;
} else {
this.update(this.val);
}
},
update: function(e) {
// console.log('update', e);
this.$emit('updated', this.val);
},
}
}
</script>