vue中计算属性和侦听属性

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>vue 入门</title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>

</head>
<body>

    <div id="app">
        姓 <input type="text" v-model='firstname'>

        名 <input type="text" v-model="lastname">

        <span>{{ fullName }}</span>
        <span>{{ count }} </span>
    </div>
    <script>
        new Vue({
            el:"#app",
            data:{
                firstname:'',
                lastname:'',
                count:0
            },
            computed:{
                fullName (){
                    return   this.firstname + this.lastname
                }
            },
            watch:{
                fullName:function(){
                    this.count++
                }
            }
           
        })
    
    </script>
</body>
</html>

 

上一篇:JavaScript 中 call()、apply()、bind() 的用法


下一篇:Vue侦听器(Vue07)