51
32

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Vue.js】autosizeなtextarea

51
Last updated at Posted at 2016-08-12

概要

ユーザーの改行にあわせて自動的に伸びるテキストエリアをVue.jsで

デモ

コード

<textarea v-model="value" :rows="rows"></textarea>
  computed:{
  	rows:function(){
    	var num = this.value.split("\n").length;
        return (num > 4) ? num : 4;
    }
  }

textareaのrows属性に\nの数をぶち込んでるだけ。

おわりに

  • Vue.jsはシンプルなコードで色々できて便利。強さを感じる。
  • 思い至るまで、伸びるテキストエリアのためだけにVueにjQueryとjQuery-autosizeを併用して依存増やしてた。
  • もっと日本語で検索可能なところに、Vueの小ネタ的記述増えてくれ。
51
32
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
51
32

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?