Within my vue component, the structure is as follows:
export default{
name: '',
data: function () {
return {
var1 :{},
var2 : {},
...
}
},
created: function () {
this.methodName1()
},
methods: {
methodName2: function () {
var context = this
rp(options).then(function () {
context.methodName1()
return null
}).catch(function (err) {
console.log(err)
})
},
methodName1: function () {
//function body
}
}
}
I'm puzzled about why this.methodName1
returns undefined whereas
var context = this;
context.methodName1
functions correctly inside the methodName2?
What is the reason for needing to reference the this
variable specifically when manipulating DOM elements?