码迷,mamicode.com
首页 > 其他好文 > 详细

Vue的watch监听事件

时间:2018-11-06 22:30:22      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:first   监听   指定   last   相关   function   input   事件   名称   

Vue的watch监听事件

相关Html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>名称案例</title>
    <script src="../js/vue-2.4.0.js"></script>
</head>
<body>
<div id="app">

    <input type="text" v-model="firstname" @keyup="getFullname">+
    <input type="text" v-model="lastname" @keyup="getFullname">=
    <input type="text" v-model="fullname">

</div>

<script>

    var vm = new Vue({

        el: "#app",
        data: {
            firstname: "",
            lastname: "",
            fullname: ""
        },
        methods: {
            getFullname: function () {
//                this.fullname = this.firstname+this.lastname;
            }
        },
        watch: {
            //使用这个可以监听data中指定数据的变化,然后触发watch中对应的function的处理
            'firstname': function (newVal,oldVal) {

                console.log((newVal + "--" + oldVal));
            },
            'lastname': function (newVal,oldVal) {
                console.log((newVal + "--" + oldVal));
            }

        }


    })


</script>


</body>
</html>

Vue的watch监听事件

标签:first   监听   指定   last   相关   function   input   事件   名称   

原文地址:https://www.cnblogs.com/charlypage/p/9918210.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!