fix: field textarea height calc wrong

This commit is contained in:
陈嘉涵 2017-08-21 21:53:52 +08:00
parent 6324fa9088
commit 306a6417d1

View File

@ -95,6 +95,14 @@ export default {
};
},
mounted() {
if (this.autosize && this.type === 'textarea') {
const el = this.$refs.textareaElement;
el.style.height = el.scrollHeight + 'px';
el.style.overflowY = 'hidden';
}
},
watch: {
value(val) {
this.currentValue = val;
@ -102,7 +110,7 @@ export default {
currentValue(val) {
if (this.autosize && this.type === 'textarea') {
this.$nextTick(() => this.sizeAdjust());
this.$nextTick(this.sizeAdjust);
}
this.$emit('input', val);
}
@ -125,12 +133,9 @@ export default {
},
sizeAdjust() {
const textareaElement = this.$refs.textareaElement;
const textAreaDiff = (parseInt(textareaElement.style.paddingBottom, 10) +
parseInt(textareaElement.style.paddingTop, 10)) || 0;
// 0 scrollHeight
textareaElement.style.height = 0 + 'px';
textareaElement.style.height = (textareaElement.scrollHeight - textAreaDiff) + 'px';
const el = this.$refs.textareaElement;
el.style.height = 'auto';
el.style.height = el.scrollHeight + 'px';
},
handleInputFocus() {