vue下textarea元素自适应高度

原理:监听input事件,获取到元素和元素的scrollHieghtscrollTop,动态改变。
代码:

<textarea  v-on:input="autoTextAreaHeight" ></textarea>

...
methods:{
    //textarea自适应高度
        autoTextAreaHeight:function(e){
            let o = e.target;
            o.style.height = o.scrollTop + o.scrollHeight + "px";
        }
}
...

猜你喜欢

转载自www.cnblogs.com/linxue/p/8855742.html