N
N
nurdus2018-07-11 16:14:54
Vue.js
nurdus, 2018-07-11 16:14:54

Why is a computed property evaluated 2 times?

Good afternoon.
When the site loads, _jobs is calculated correctly, BUT literally a second later _jobs is updated and the property fields being changed become undefined, the only way to avoid this is to check for undefined. I don't understand why this is happening?
Computed property:

computed: {
    _jobs: function() {
      let self = this
      let tjobs = _.map(this.jobs, function(job) {
        _.mapKeys(self.utils, function(field, fieldKey) {
          if (field[job[fieldKey]]) { // без этого if возвращается undefined
            job[fieldKey] = field[job[fieldKey]]
          }
          return job
        })
        return job
      })
      return tjobs
    }
  }

utils.js:
export const utils = {
  kind: {
    job: "clock",
    notice: "file-text",
    control: "check-circle"
  },
  state: {
    work: "В работе",
    done: "Выполнено",
    breakk: "Прекращено"
  }
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question