Vuejs의 데이터 바인딩

이 문서에서는 많은 응용 프로그램이 있는 특히 흥미로운 기능을 살펴보겠습니다. 데이터 바인딩이라고 하는 것입니다. 기본적으로 프레임워크를 통해 html 태그의 속성을 Vue 인스턴스에서 제공하는 값으로 매핑할 수 있습니다. 예를 들어 입력 필드의 값을 바인딩할 수 있습니다.

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <!-- importing vue js dev library -->
    <!-- development version, includes helpful console warnings -->
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <title>My vue Test</title>
</head>
<body>
    <div id="app">
        What's your name?
        <br>
        <input type="text" name="name" v-bind:value="name">
        <br>
        <button v-on:click="changeName()">
            change name
        </button>
    </div>
    <script type="text/javascript">
        var app = new Vue({ //instantiating the vue instance
          el: '#app', //we select where vue is going to work in the DOM
          data: {
            name: 'Mattia'//this are the data
          },
          methods: {
            changeName: function() {
                this.name = "Martino";
            }
          }
        })
    </script>
</body>
</html>


이것은 결과 페이지입니다.


버튼을 클릭하면 필드에 값으로 표시된 이름이 즉시 변경됩니다.

좋은 웹페이지 즐겨찾기