ant-design-vue/components/table/demo/EditableCell.vue

55 lines
970 B
Vue
Raw Normal View History

2018-04-01 14:33:01 +00:00
<template>
2019-02-01 09:23:00 +00:00
<div class="editable-cell">
<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>
2018-04-01 14:33:01 +00:00
</div>
</template>
<script>
export default {
props: {
text: String,
},
data () {
return {
value: this.text,
editable: false,
2019-01-12 03:33:27 +00:00
};
2018-04-01 14:33:01 +00:00
},
methods: {
handleChange (e) {
2019-01-12 03:33:27 +00:00
const value = e.target.value;
this.value = value;
2018-04-01 14:33:01 +00:00
},
check () {
2019-01-12 03:33:27 +00:00
this.editable = false;
this.$emit('change', this.value);
2018-04-01 14:33:01 +00:00
},
edit () {
2019-01-12 03:33:27 +00:00
this.editable = true;
2018-04-01 14:33:01 +00:00
},
},
2019-01-12 03:33:27 +00:00
};
2018-04-01 14:33:01 +00:00
</script>