LoginSignup
0
0

More than 3 years have passed since last update.

【Vue.js】v-modelを使った双方向データバインディングについて

Posted at

v-model、双方向データバインディングについて少しだけまとめ。

データバインディングとは?

データを結びつけること

双方向とは?

vueの記述を変えると、HTML側も書き変わるような仕組み。

簡単なコード

<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>

<div id="app">
<input type="text" v-model="message"> 
  <h1>{{message}}</h1>
</div>
new Vue({
    el: '#app',
  data: {
    message: 'がんばれ'
  }
})

これで下のような表示になるが、ここで文字を入力すると、リアルタイムでh1タグで囲んでいるmessageの文字も変わる。

スクリーンショット 2021-03-03 20.36.40.png

これがv-model。

0
0
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
0
0