Y
Y
Yaroslav2018-04-13 15:29:13
Vue.js
Yaroslav, 2018-04-13 15:29:13

Why is the computed method not firing in vue?

There is a method:

parse: function () {
      var vm = this;
    var data = $('#form-one-ass').val();
    var rows = data.split("\n");
    var tmpWorkOrders = [];
    for(var y in rows) {
      var cells = rows[y].split("\t");
      tmpWorkOrders.push({
      NUMBER: cells[0],
      SUM: parseFloat(cells[1]),
      DATE: cells[2],
      CONTRACTOR: cells[3]
      });
      this.form.workOrders = Object.assign([], vm.form.workOrders, tmpWorkOrders);
                  //this.form.workOrders = Object.assign([], this.form.workOrders, tmpWorkOrders);
    };
    }

There are computed:
sumShipping: function () {
      var sum = 0;
    this.form.workOrders.forEach(function (val, i) {
      sum += val.SUM;
    });
    return sum;
    }

Changes to the DOM happen (table insert) but computed doesn't fire (sum).
What nuance in vue did I omit?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
Yaroslav, 2018-04-13
@CubaJas

It's not about Vue, it calculates everything normally. The fact is that in the parse method it was necessary to do a normal check for creating an array, it generated the last empty string with the NaN sum and the summation in computed did not work.

E
Evgeny Kulakov, 2018-04-13
@kulakoff Vue.js

sumShipping is generally used somewhere or just declared?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question