LoginSignup
24
11

More than 5 years have passed since last update.

Vue.jsでチェックボックスやラジオボタンに初期値を入れる方法

Last updated at Posted at 2016-12-22

vueを学ぶためにTODOアプリを作っていた際、チェックボックスに初期値を入れるうまい方法は無いかなーと探していた時の備忘録。

結論

<input type="checkbox" :checked="true"/>

trueとなっている部分にはデータプロパティなどを入れることができる。
例えば簡素なTODOアプリであれば、以下のようになる。

<tbody v-for="todo in todos">
  <tr>
    <td>{{ todo.name }}</td>
    <td><input type="checkbox" :checked="todo.done"/></td>
  </tr>
</tbody>

todo.doneがtrueならばチェックされた状態になる。

参考

最後に

もし間違っている部分や、ここはもっと良い書き方がある!などございましたら、どんなに些細な事でも構いません。
すぐに修正しますのでお気軽にお申し付け下さい。

24
11
0

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
24
11