Vue中怎么利用watch监听数组

今天就跟大家聊聊有关Vue中怎么利用watch监听数组,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

成都创新互联公司于2013年创立,是专业互联网技术服务公司,拥有项目成都网站建设、网站建设网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元城中做网站,已为上家服务,为城中各地企业和个人服务,联系电话:13518219792

1.普通的watch

data() {
  return {
    frontPoints: 0
  }
},
watch: {
  frontPoints(newValue, oldValue) {
    console.log(newValue)
  }
}

2.数组的watch:深拷贝

data() {
  return {
    winChips: new Array(11).fill(0)
  }
},
watch: {
  winChips: {
    handler(newValue, oldValue) {
      for (let i = 0; i < newValue.length; i++) {
        if (oldValue[i] != newValue[i]) {
          console.log(newValue)
        }
      }
    },
    deep: true
  }
}

3.对象的watch

data() {
  return {
    bet: {
      pokerState: 53,
      pokerHistory: 'local'
    }
  }
},
watch: {
  bet: {
    handler(newValue, oldValue) {
      console.log(newValue)
    },
    deep: true
  }
}

4.对象的具体属性的watch:

data() {
  return {
    bet: {
      pokerState: 53,
      pokerHistory: 'local'
    }
  }
},
computed: {
  pokerHistory() {
    return this.bet.pokerHistory
  }
},
watch: {
  pokerHistory(newValue, oldValue) {
    console.log(newValue)
  }
}

看完上述内容,你们对Vue中怎么利用watch监听数组有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注创新互联行业资讯频道,感谢大家的支持。


名称栏目:Vue中怎么利用watch监听数组
文章URL:http://bzwzjz.com/article/pddpip.html

其他资讯

Copyright © 2007-2020 广东宝晨空调科技有限公司 All Rights Reserved 粤ICP备2022107769号
友情链接: 高端网站设计 企业网站制作 高端网站建设 响应式网站建设 网站建设开发 网站建设费用 企业网站建设 定制级高端网站建设 app网站建设 成都响应式网站建设 网站制作公司 网站制作 成都网站建设 成都网站建设 温江网站设计 成都企业网站制作 手机网站制作设计 网站制作 手机网站建设套餐 手机网站建设 成都商城网站建设 高端定制网站设计