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

来源:2-5 Vue中的计算属性和侦听器

qq_慕码人8528369

2019-08-25 19:03

<!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

写回答 关注

1回答

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

    watch

    慕码人022... 回复DCFY

    match watch

    2020-04-15 14:49:31

    共 3 条回复 >

vue2.5入门

快速理解Vue编程理念上手Vue2.0开发。

146820 学习 · 657 问题

查看课程

相似问题