VUE watch多个data数据

2020-04-20  本文已影响0人  callPromise
data() {
  return {
    num1: 0,
    num2: 0,
    num3: 0,
    count: 0
  }
},
computed{
  num() {
    const { num1, num2, num3 } = this
    return { num1, num2, num3 }
  }
},
watch: {
  num: {
    handler(obj) {
      const { num1, num2, num3 } = obj
      this.count = this.plusU(num1, num2, num3)
    },
    immediate: true,
    deep: true
  }
},
method: {
  plusU(n1, n2, n3) {
    return n1 + n2 + n3
  }
}
上一篇下一篇

猜你喜欢

热点阅读