问答详情
源自:2-5 Vue中的计算属性和侦听器

count数值为什么不会增加

<!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:value="firstName">
        名:<input v-model:value="lastName">
        <div>{{fullName}}</div>
        <div>{{count}}</div>
    </div>

    <script>
        new Vue({
            el:"#root",
            data:{
                firstName:"",
                lastName:"",
                count: 0
 },
            computed:{
                fullName: function () {
                    return this.firstName+" "+this.lastName
 }
            },
            watch:{
                firstName: function () {
                    this,count++
                }
            }
        })
    </script>
</body>
</html>


提问者:积极废人_ 2018-09-02 17:14

个回答

  • AnxiangLemon
    2018-09-02 18:32:10
    已采纳

    https://img3.mukewang.com/5b8bbbf400017d8104340127.jpg  

    ①你的点写成了逗号 

     ②firstName 改成 fullName即可