The issue I am facing is while using vue.js, but I believe it might also be applicable in plain JS. The problem arises when I am inside a function that is within another function; I have to reference variables by their full path such as Object.variable instead of simply using this.variable. Is there a way to access variables like this.timer and this.pages directly, instead of having to specify TVComponent.timer or TVComponent.pages?
const TVComponent = new Vue ({
el: '.tvContent',
data:
{
current_page: 0,
timer: 0,
pages: [
{ page: '/', interval: 10 },
{ page: 'tv/calls', interval: 10 },
{ page: 'tv/general', interval: 10 }
]
},
methods:
{
tvTimer()
{
setInterval(function() {
TVComponent.timer++;
if (TVComponent.timer == TVComponent.pages[TVComponent.current_page].interval) {
console.log('it is time!!');
}
console.log(TVComponent.pages[TVComponent.current_page].page);
}, 1000);
},
})