1
0

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 3 years have passed since last update.

Vue.js v-modelで値をバインドする方法

Last updated at Posted at 2022-03-27

概要

v-modelによって,入力された値をVueで定義したプロパティの値にバインドする機能について記載します。

記述方法

<input v-model="変数名">

変数名にはVueオブジェクト内に定義した変数の名前を指定します。

実例

<body>
    <h1>Vue.js</h1>
    <div id="app">
        <div><test v-bind:name="name" /></div>
        <div><input type="text" v-model="name"></div>
    </div>

    <script>
        var test = Vue.component('test',
        {
            props:['name'],
            template: '<p class="test">{{ name }}!</p>',
        })

        var app = new Vue({
            el: '#app',
            data:{
                name:''
            }
        });
    </script>
</body>

添付した画像のようにテキストエリアに入力した値が出力されます。
スクリーンショット 2022-03-27 17.02.40.png

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?