I am newly learning Javascript and vue.js. I am getting confused while accessing member variables of internal object inside an object in Vue.js as it is different from Javascript.
Assume below object in javscript,
let obj = {
name : 'n',
ob : {
c : 'char',
d : 'int'
},
printcd : function()
{
console.log(this.ob.c);
console.log(this.ob.d);
}
}
We are accessing 'c' and 'd' through ob (like this.ob.c). But below is the Vue.js code
ap = new Vue(
{
el: "#app",
data:
{
name:
{
first: 'First',
last:'Last',
age: 30
}
},
computed:
{
getName: function() {
return this.name.first + ' ' + this.name.last;
}
}
}
Here we are accessing first and last in getName() without using data. We are accessing this.name.first instead of this.data.name.first. Can any one please let me know why the accessing mechanism is different.