mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-26 11:26:35 +08:00
fix: field textarea height calc wrong
This commit is contained in:
parent
6324fa9088
commit
306a6417d1
@ -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: {
|
watch: {
|
||||||
value(val) {
|
value(val) {
|
||||||
this.currentValue = val;
|
this.currentValue = val;
|
||||||
@ -102,7 +110,7 @@ export default {
|
|||||||
|
|
||||||
currentValue(val) {
|
currentValue(val) {
|
||||||
if (this.autosize && this.type === 'textarea') {
|
if (this.autosize && this.type === 'textarea') {
|
||||||
this.$nextTick(() => this.sizeAdjust());
|
this.$nextTick(this.sizeAdjust);
|
||||||
}
|
}
|
||||||
this.$emit('input', val);
|
this.$emit('input', val);
|
||||||
}
|
}
|
||||||
@ -125,12 +133,9 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
sizeAdjust() {
|
sizeAdjust() {
|
||||||
const textareaElement = this.$refs.textareaElement;
|
const el = this.$refs.textareaElement;
|
||||||
const textAreaDiff = (parseInt(textareaElement.style.paddingBottom, 10) +
|
el.style.height = 'auto';
|
||||||
parseInt(textareaElement.style.paddingTop, 10)) || 0;
|
el.style.height = el.scrollHeight + 'px';
|
||||||
// 需要先设为0, 才可以让scrollHeight正确计算。
|
|
||||||
textareaElement.style.height = 0 + 'px';
|
|
||||||
textareaElement.style.height = (textareaElement.scrollHeight - textAreaDiff) + 'px';
|
|
||||||
},
|
},
|
||||||
|
|
||||||
handleInputFocus() {
|
handleInputFocus() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user