I created a vue component with TypeScript, and I\'m getting this error in data()
and in methods()
:
Property \'xxx\' does not exist
You need to use function
in the correct way to preserve the reference of this.
methods: {
toggle() {
this.open = !this.open
if (this.open) {
// Add click listener to whole page to close dropdown
document.addEventListener('click', this.close)
}
},
close() {
this.open = false;
document.removeEventListener('click', this.close)
}
}