LoginSignup
0
0

More than 1 year has passed since last update.

【Vue.js】v-bindによる双方向バインディングの仕組み

Last updated at Posted at 2021-12-03

case

v-bindで双方向のバインディングを行う場合,
入力された値が格納されている$event.target.valueへvue側が参照している状態になる。
これをシンプルに記述できるようにしているのがv-modelディレクティブ

<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Document</title>
</head>
<body>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.11/dist/vue.js"></script>
    <div id="app">
        <input :value="test" @input="test = $event.target.value"> //この部分
    </div>

    <script>
        let app = new Vue({
            el:'#app',
            data(){
                return {
                    test:'aaa'

                }
            }
        })
    </script>
</body>
</html>
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