欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Vue開發(fā)之watch監(jiān)聽數(shù)組、對象、變量操作分析

 更新時(shí)間:2019年04月25日 10:40:09   作者:guanguan0_0  
這篇文章主要介紹了Vue開發(fā)之watch監(jiān)聽數(shù)組、對象、變量操作,結(jié)合實(shí)例形式分析了vue.js使用Watch針對數(shù)組、對象、變量監(jiān)聽相關(guān)操作技巧,需要的朋友可以參考下

本文實(shí)例講述了Vue開發(fā)之watch監(jiān)聽數(shù)組、對象、變量操作。分享給大家供大家參考,具體如下:

1.普通的watch

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

2.數(shù)組的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.js程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評論