在我的import axios from "axios";
文件中导入axios App.vue
之后,出现了axios is defined but never used
错误。我附上了错误图片和package.json
代码。我安装了axios
。如何解决?
package.json文件为:
{
"name": "myvue",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
"dependencies": {
"@mdi/font": "^3.6.95",
"@vue/test-utils": "^1.0.0-beta.29",
"axios": "^0.19.0",
"core-js": "^3.3.2",
"material-design-icons-iconfont": "^5.0.1",
"roboto-fontface": "*",
"vue": "^2.6.10",
"vuetify": "^2.1.10"
},
"devDependencies": {
"@vue/cli-plugin-babel": "^4.0.0",
"@vue/cli-plugin-eslint": "^4.0.0",
"@vue/cli-service": "^4.0.0",
"babel-eslint": "^10.0.3",
"eslint": "^5.16.0",
"eslint-plugin-vue": "^5.0.0",
"sass": "^1.19.0",
"sass-loader": "^8.0.0",
"vue-cli-plugin-vuetify": "^2.0.2",
"vue-template-compiler": "^2.6.10",
"vuetify-loader": "^1.3.0"
}
}
答案 0 :(得分:12)
您可以通过更新package.json
下的"eslintConfig"
文件来解决此问题,例如:
...
"rules": {
"no-console": "off",
"no-unused-vars": "off"
}
...
答案 1 :(得分:2)
这更是警告而不是错误,但它被设置为eslint
文件中的错误。
这只是说您没有使用axios
,而是导入了它。该规则可以确保您使用的是已定义的每个变量。
答案 2 :(得分:2)
您没有在App.vue文件的任何地方使用它。
删除该导入,并查看其是否有效。
答案 3 :(得分:1)
转到package.json
文件中查找eslintConfig
包含具有以下属性的rules
对象。
"eslintConfig": {
"rules": {
"no-unused-vars": "off",
"no-console": [
"warn",{ "allow":[ "clear", "info", "error", "dir", "trace", "log"]}
],
}
},
没有使用的变量 如果未使用v-for指令或范围属性,此规则将报告它们的变量定义。