This variable is defined inside data
:
data () {
return {
isSent: false,
(...)
When trying to call the method here:
methods: {
sendEmail () {
let isSent = this.isSent
const xhr = new XMLHttpRequest()
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
console.log(xhr.responseText)
this.isSent = true
(...)
linter says there is an unused variable defined. When I remove the let isSent...
initialization, linter says about undefined variable.
I saw the Q&A related to JS closures, but information there, although useful and broad, is very general and doesn't solve more specific issues like this one.
How should I get to the variable from inside the xhr
function?