我正在使用Axios提交发布请求,如果请求成功,我想给用户一些确认。但是,我没有用过response
变量,所以出现了eslint
错误。该如何解决?
axios.post('/api/option.json', {
choices: myChoices
})
.then(response => {
alert('Form was submitted successfully')
})
错误:
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
答案 0 :(得分:8)
已定义“变量”但从未使用过,此错误仅表示您声明的变量未在程序中使用。
解决方案-
在程序中,将响应用作返回值。
Lock
OR
如果您不喜欢vue.js的此功能,可以通过在package.json文件中添加此对象来关闭。
axios.post("/api/option.json", {
choices: myChoices;
})
.then(response => {
alert("Form was submitted successfully");
return response
});
答案 1 :(得分:0)
那是我发现的最佳解决方案:
axios.post('/api/option.json', {
choices: myChoices
})
.then(() => {
alert('Form was submitted successfully')
})