Quantcast
Channel: CSSタグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 9004

Vue3 での textareaの高さを自動で設定する方法

$
0
0
結論 Vue props: { text: String, id: String, }, data() { return { txt: this.text, i: this.id, } }, computed:{ rows() { if(this.txt === null) { return 4 } else{ let num = (this.txt.match(/\n/g) || []).length + 1 return (num > 4) ? num : 4 } } } HTML <textarea class="editable-contents-textarea" v-on:blur="saveText" v-model="txt" :id="'textarea'+ i" :rows="rows"></textarea> css .editable-contents-textarea{ height:auto; } 補足 rows関数の4って言う数字は適当です.強いて言うなら最低の行数ですね あと,if(this.txt === null)の分岐なんですけど,これはtexareaに文字がない場合のものです. 以上です

Viewing all articles
Browse latest Browse all 9004

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>