zoukankan      html  css  js  c++  java
  • vue 之监听事件----2.watch

    <!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>Document</title>
      <script src="js/vue.js"></script>
    </head>
    
    <body>
      <div id="app">
        <input type="text" v-model="firstname">+
        <input type="text" v-model="lastname">=
        <input type="text" v-model="fullname">
      </div>
    
      <script>
        //创建Vue实例,得到 ViewModel
        var vm = new Vue({
          el: '#app',
          data: {
            firstname: '',
            lastname: '',
            fullname: ''
          },
          methods: {},
          watch: { //使用这个属性,可以监视data中指定数据的变化,然后触发这个watch中对应的function处理函数
            firstname: function (newVal, oldVal) { //function可加可不加引号,但当时连字符命名时,必须要加
              // this.fullname=this.firstname + '-' + this.lastname;
              this.fullname = newVal + '-' + this.oldVal;
            },
            lastname:function(newVal){
              this.fullname=this.firstname +"-" + newVal;
            }
          }
        });
      </script>
    </body>
    
    </html>
  • 相关阅读:
    [CLYZ2017]day8
    [CLYZ2017]day12
    [bzoj1503][NOI2004]郁闷的出纳员
    [CLYZ2017]day18
    [CLYZ2017]day11
    [CLYZ2017]day17
    在DLL中获取服务器路径
    SPSecurity.RunWithElevatedPrivileges 拒绝访问
    prototype1.4.0(转载)
    删除多表数据
  • 原文地址:https://www.cnblogs.com/linm/p/12522123.html
Copyright © 2011-2022 走看看