vue 计算列表内的数值占比

vue yekong 388℃

vue 计算列表内的数值占比

  computed: {
    list2: function () {
      let total = 0
      var list2 = this.list;
      var list = []
      this.list.forEach((type) => {
        total = total + type.value
      });
      list2.forEach((type) => {
        var data = {
          value: type.value,
          percentage: Number((type.value / total) * 100).toFixed(2),
          label: type.label
        }
        list.push(data)
      });
      return list
    }
  },
喜欢 (0)