关于vue3.0使用axios报错问题

2022-10-14,

这篇文章主要介绍了vue3.0使用axios报错问题记录,vue-cli3.0安装插件的时候要注意区分vue-cli2.0的命令,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下

vue-cli3.0使用axios的时候出现错误,记录一下

报错信息:

Uncaught TypeError: Cannot set property $axios of #<Vue> which has only a getter
at eval (main.js?56d7:12)
at Module../src/main.js (app.js:11102)
at __webpack_require__ (app.js:724)
at fn (app.js:101)
at Object.0 (app.js:11283)
at __webpack_require__ (app.js:724)
at app.js:791
at app.js:794

vue-cli3.0安装插件的时候要注意区分vue-cli2.0的命令

安装:

//vue-cli2.0命令
$ npm install axios
//vue-cli3.0命令
$ npm add axios

使用:

1.首先在main.js里边把axios实例挂载到Vue原型上
  坑点: 命名的时候不能使用"axios"这个字段
import axios from 'axios'
Vue.prototype.$ajax = axios
2.在需要发送请求的地方使用"$ajax"
this.axioss.get('/api/seller')
        .then(function(res){
            console.log(res);
            this.seller = res.data;
        })
        .catch(function(error){
            console.log(error);
        })

到此这篇关于vue3.0使用axios报错问题记录的文章就介绍到这了,更多相关vue3.0使用axios报错内容请搜索北冥有鱼以前的文章或继续浏览下面的相关文章希望大家以后多多支持北冥有鱼!

您可能感兴趣的文章:

  • Vue3全局挂载使用Axios学习实战
  • vue3如何实现挂载并使用axios
  • Vue3在Setup中使用axios请求获取的值方式
  • Vue3如何使用axios发起网络请求
  • vue3学习笔记简单封装axios示例实现
  • vue3 axios 实现自动化api配置详解

《关于vue3.0使用axios报错问题.doc》

下载本文的Word格式文档,以方便收藏与打印。