How can i access to data values inside itself in vue.js?
Code:
data: function(){
return {
foo: 123,
bar: this.foo
}
}
In this case I got undefined
There are several options I see:
data: function(){
const data = {
foo: 123
};
data.bar = data.foo;
return data;
}
or
data: function(){
const data = {
foo: 123
};
return {
...data,
bar: data.foo
};
}
You've got undefined because of this.foo refers to function(){`s context, not object`s context.