In vuecli I have data like this
data() {
return {
options: [{
values: ['a', 'b', 'c']
}],
variants: [],
p: {
option_1: null
}
}
}
and when i run a loop inside a method that looks like this
methods: {
add() {
for(let i = 0; i < this.options[0].values.length; i++) {
(function(i, p){
var raw = p;
raw.option_1 = this.options[0].values[i];
this.variants.push(raw);
})(i, this.p);
}
}
}
I tried in many ways but succeed only when I set the value of raw
inside the loop likevar raw = {option_1: null}
.
But this is not what i want. I want to take values from data
and use it in the loop to produce
variants: [{ option_1: 'a' }, { option_1: 'b' }, { option_1: 'c' }]
How can I accomplish this ??