watch

1 监听对象时

watch: {
    spobj: {
      handler: function (val, neval) {
        this.initChart(this.line)
      },
      deep: true// 对象内部的属性监听,也叫深度监听
    }
  },

2 监听数组

 watch: {
    statdata (nnn, ooo) {
      let that = this
      let num1 = ((that.statdata[0]) / (that.sum != null ? that.sum : 1) * 100).toFixed(2)
      let num2 = ((that.statdata[1]) / (that.sum != null ? that.sum : 1) * 100).toFixed(2)
      let num3 = ((that.statdata[2]) / (that.sum != null ? that.sum : 1) * 100).toFixed(2)
      let first = that.statdata[0] === undefined ? 0 : ((num1 > 0) ? num1 : 0)
      let seconde = that.statdata[1] === undefined ? 0 : ((num2 > 0) ? num2 : 0)
      let third = that.statdata[2] === undefined ? 0 : ((num3 > 0) ? num3 : 0)
      let forth = that.sum != 1 && that.sum != null ? ((100 - first - seconde - third).toFixed(2) > 0 ? (100 - first - seconde - third).toFixed(2) : 0) : 0
      this.initChart(first, seconde, third, forth)
    }

// 是一个复合数组,每个元素是个对象
  arra(nnn, ooo) {
      this.efmobj.factoryname = this.arra.length != 0 ? this.arra[0].factoryID : null
      this.getlinedata(this.efmobj.factoryname)
    },

你可能感兴趣的:(watch)