Axios已定义但从未使用过

时间:2019-11-21 15:19:08

标签: vue.js axios

在我的import axios from "axios";文件中导入axios App.vue之后,出现了axios is defined but never used错误。我附上了错误图片和package.json代码。我安装了axios。如何解决?enter image description here

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"
  }
}

4 个答案:

答案 0 :(得分:12)

您可以通过更新package.json下的"eslintConfig"文件来解决此问题,例如:

...

"rules": {
  "no-console": "off",
  "no-unused-vars": "off"
}

...

答案 1 :(得分:2)

这更是警告而不是错误,但它被设置为eslint文件中的错误。

这只是说您没有使用axios,而是导入了它。该规则可以确保您使用的是已定义的每个变量。

以下是该规则的文档:https://eslint.org/docs/rules/no-unused-vars

答案 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指令或范围属性,此规则将报告它们的变量定义。