vue 계산 속성 및 감청기

6914 단어
DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>        title>
    <script src="Vue.js">script>
head>
<body>
<div id="root"><input v-model="firstName"/><input v-model="lastName"/>
    <div>{{Name}}div>
    <div>{{count}}div>
div>
<script>
    new Vue({
        el:"#root",
        data:{
            firstName:"",
            lastName:"",
            count:0
        },
        
        computed:{
            Name:function () {
                return this.firstName+this.lastName;
            }
        },
        
        watch:{
            /*firstName:function () {
                this.count++;
            },
            lastName: function()
            {
                this.count++;
            }*/
            Name:function () {
                this.count++;
            }
        }

    })
script>
body>
html>

좋은 웹페이지 즐겨찾기