I'm submitting a Post request using Axios, and I want to give the user some confirmation if the request is successful. However, I have no use for the response
variable, so I get an eslint
error. How to fix this?
axios.post('/api/option.json', {
choices: myChoices
})
.then(response => {
alert('Form was submitted successfully')
})
Error:
Module Error (from ./node_modules/eslint-loader/index.js):
error: 'response' is defined but never used (no-unused-vars) at src/components/Options.vue:78:15
EDIT (April 2020): Oops, looks like this question now has 1k views but 0 upvotes. I'm guessing I wrote a tantalizing title but the question isn't helping people. Please comment if I should rename this or link to a better question?
'variable' is defined but never used, this error simply means the variable that you declared is not used in the program.
Solution -
In your program use response as the return value.
axios.post("/api/option.json", {
choices: myChoices;
})
.then(response => {
alert("Form was submitted successfully");
return response
});
OR
axios.post("/api/option.json", {
choices: myChoices;
})
.then(() => {
alert("Form was submitted successfully");
});
OR
If you do not like this feature of eslint you can turn off by adding this object in package.json file.
"eslintConfig": {
"rules": {
"no-console": "off",
"no-unused-vars": "off"
}
},
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With