所以我想将 Axios 添加到 Vue 项目中。我通过发行vue add axios. 它告诉我,安装成功,但后来不知何故出现了 5 个错误。我不完全明白为什么它告诉我它已安装,但似乎仍有一些工作在进行,更重要的是:这个错误是什么?
我猜它实际上安装了 Axios 但它无法生成它通常添加的默认代码?那不好吗?为什么要添加代码?为什么我不能将它用作一种依赖管理器?
$ 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.
Run Code Online (Sandbox Code Playgroud)
我猜,您创建了一个项目,并且在其中使用了 eslint(Linter / Formatter)。这是它的典型错误。只需打开src/plugins/axios.js文件并删除options第 42 行的变量。来自:
Plugin.install = function(Vue, options) {
Run Code Online (Sandbox Code Playgroud)
到:
Plugin.install = function(Vue) {
Run Code Online (Sandbox Code Playgroud)
这应该可以解决您的问题,并且不会产生任何后果。无论如何,您没有使用该变量。
Axios 就像它说成功安装一样。安装后,一个文件会添加到您的项目中,以便您可以将其用于全局请求。该文件的最新版本于 2 年前更新vue-cli-plugin-axios。
如果您只想将 axios 作为依赖项添加到您的项目中npm install axios,然后像往常一样手动导入import axios from 'axios';
| 归档时间: |
|
| 查看次数: |
1380 次 |
| 最近记录: |