Answer the question
In order to leave comments, you need to log in
Vue calculate and write a new property to the object (this.$set is not a function)?
Hello, the question is the following: there is an array of objects that needs to be drawn as a list,
but before drawing, you need to calculate a new property and enter it into the object
, I do it like this
computed: {
calculatedTables:function () {
for (let table in this.tables) {
this.$set(table, 'datetime',555)
console.log(table)
}
}
(in promise) TypeError: this.$set is not a function
Answer the question
In order to leave comments, you need to log in
computed - must only perform a calculation and return a result, it must not mutate the data.
Use methods or watch to change data
You can't mutate in computed
If you need to add an object field, you can use .map
return this.tables.map(table => ({ ...table, datetime: 555 }))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question