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

数据改变后触发不了监听器是怎么回事

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>监听器</title>
    <script src="https://cdn.jsdelivr.net/npm/vue"></script>
</head>
<body>
<div id="root">
</div>
<script>
    new Vue({
        el: "#root",
        template: `<div >
                     <input v-model="firstName">
                     <input v-model="lastName">
                     <div>{{fullName}}</div>
                     <div>{{number}}</div>
                   </div>`,
        data: {
            firstName: "",
            lastName: '',
            number: 0,
        },
        computed: {
            fullName: function () {
                return this.firstName + this.lastName
            }
        },
        match: {
            fullName: function () {
                console.log('数据发生了改变')
                this.number++
            }
        }
    })
</script>
</body>
</html>

https://img4.mukewang.com/5d626ae9000181a119140360.jpg

提问者:qq_慕码人8528369 2019-08-25 19:03

个回答

  • 慕移动6321207
    2019-08-26 00:18:08
    已采纳

    watch