I have a vue component with following structure:
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
}
}
My doubt is why this.methodName1
gives undefined where as
var context = this;
context.methodName1
works perfectly fine inside the methodName2?
Why do we need to reference the this
variable especially to modify the DOM elements?