zoukankan      html  css  js  c++  java
  • Vue之watch监听对象中某个属性的方法

    新建 userinfo = { name: "小明",  age: "18", }

      vue中watch监听name的方法

      1. 可以结合计算属性的方法实现

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    {
      ......
       watch: {
         nm () {
           console.log(this.nm)
         }
       },
        computed: {
          nm () { return this.userinfo.name }
       }
      ...... 
    }

      2. 可以通过配置 deep 为true实现

    复制代码
    // 监听对象的某个值
    {
      ......
       watch: {
         'userinfo.name' () {
           console.log(this.nm)
         }
       }
      ......  
    }
    
    // 直接监听整个属性,消耗大
    {
      ......
       watch: {
         userinfo () {
           handler () {
               console.log(this.nm)
           },
           deep: true
         }
       }
      ......  
    }        

     转自:https://www.cnblogs.com/jingxuan-li/p/11817329.html

  • 相关阅读:
    Spring Boot自动配置
    Servlet、JSP总结(1)
    Spring MVC
    Springboot中的数据库事务
    数据库访问
    AOP
    全注解下的IOC
    spring boot入门
    安卓工程化开发笔记(2)
    2048功能说明模板
  • 原文地址:https://www.cnblogs.com/javalinux/p/15709642.html
Copyright © 2011-2022 走看看