3

so I wanted to add Axios to a Vue project. I did that by issuing vue add axios. It told me, the installation was successful but then I somehow get 5 errors. I don't fully get why it tells me it was installed when it seems there are still some jobs going on and more important: What is this error about??

I guess that it actually installed Axios but it wasn't able to generate that default code it usually adds? Is that bad? Why does it add code? Why can't I just use it as kind of a dependency manager?

    $ vue add axios 
     WARN  There are uncommited changes in the current repository, it's recommended to commit or stash them first.
    ? Still proceed? Yes
      Installing vue-cli-plugin-axios...
    + vue-cli-plugin-axios@0.0.4
    updated 1 package and audited 25608 packages in 10.502s
    40 packages are looking for funding
      run `npm fund` for details
    found 0 vulnerabilities
    ✔  Successfully installed plugin: vue-cli-plugin-axios
      Invoking generator for vue-cli-plugin-axios...
    ⠋  Running completion hooks...error: 'options' is defined but never used (no-unused-vars) at src/plugins/axios.js:42:32:
  40 | );
  41 | 
> 42 | Plugin.install = function(Vue, options) {
     |                                ^
  43 |   Vue.axios = _axios;
  44 |   window.axios = _axios;
  45 |   Object.defineProperties(Vue.prototype, {


1 error found.
4

1 回答 1

10

我猜,您创建了一个项目,并且在其中使用了 eslint (Linter / Formatter)。这是一个典型的错误。只需打开src/plugins/axios.js文件并删除options第 42 行的变量。来自:

Plugin.install = function(Vue, options) {

至:

Plugin.install = function(Vue) {

这应该可以解决您的问题,并且不会产生任何后果。无论如何,您都没有使用该变量。

axios就像它说的安装成功。安装后,一个文件将添加到您的项目中,以便您可以将其用于全局请求。这个文件的最后一个版本是在 2 年前更新的vue-cli-plugin-axios

如果您只想将 axios 作为依赖项添加到项目中npm install axios,然后像往常一样手动导入它import axios from 'axios';

于 2020-03-25T14:14:35.743 回答