今天在项目中使用axios时发现axios.all() 方法可以执行但是控制台报错,后来在论坛中看到是由于axios.all() 方法并没有挂载到 axios对象上,需要我们手动去添加
== 只需要在你封装的axios文件里加入 ==
instance.all = axios.all
就完美解决了!
补充知识:vue项目中使用axios.all处理并发请求报_util2.default.axios.all is not a function异常
报错:
_util2.default.axios.all is not a function
代码:
init () { util.axios.all([this.getCourseInit(), this.getConfirmInit()]) .then(util.axios.spread((indexRes, confirmRes) => { // 两个请求现在都执行完成 this.classData = indexRes.data.today_course.map(item => { item.time = timeUtil.formatDate2Str(item.start_time, 'HH:mm') + '~' + timeUtil.formatDate2Str(item.end_time, 'HH:mm'); return item; }); this.count.count_course_today = indexRes.data.count.count_course_today; this.count.count_student_not = indexRes.data.count.count_student_not; this.count.count_student_all = indexRes.data.count.count_student_all; this.count.count_teacher_all = indexRes.data.count.count_teacher_all; this.isLoading = false; })); }, getCourseInit () { return util.axios.get('/index'); }, getConfirmInit () { return util.axios.get('/course-confirm'); },
原因:
axios实例没有all这个方法,all是axios的静态方法
解决办法:
以下方法不是最好的,还没找到更好的解决办法,目前先这样解决。
// 引入axios import axios from 'axios'; init () { axios.all([this.getCourseInit(), this.getConfirmInit()]) .then(axios.spread((indexRes, confirmRes) => { // 两个请求现在都执行完成 this.classData = indexRes.data.today_course.map(item => { item.time = timeUtil.formatDate2Str(item.start_time, 'HH:mm') + '~' + timeUtil.formatDate2Str(item.end_time, 'HH:mm'); return item; }); this.count.count_course_today = indexRes.data.count.count_course_today; this.count.count_student_not = indexRes.data.count.count_student_not; this.count.count_student_all = indexRes.data.count.count_student_all; this.count.count_teacher_all = indexRes.data.count.count_teacher_all; this.isLoading = false; })); }, getCourseInit () { return util.axios.get('/index'); }, getConfirmInit () { return util.axios.get('/course-confirm'); },
以上这篇解决vue 使用axios.all()方法发起多个请求控制台报错的问题就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com
暂无评论...
更新日志
2024年09月20日
2024年09月20日
- 《神话时代:重述版》评测:粉丝们的朝花夕拾
- 战锤40K星际战士2先锋职业介绍|先锋职业技能效果一览
- 战锤40K星际战士2重装职业介绍|重装职业技能效果一览
- 交错战线能源发电站推荐角色一览
- 阿波罗乐神之音《第4集出埃及记》[WAV+CUE]
- JohnWrightTrio-SouthSideSoul-1960-2024(24-192)
- AnthonyBruno-Cefalu(2024)[24-96]
- 《地狱潜者2》玩家人数飙升:终于不再削弱玩家了
- 黑神话引力!外媒分享孙悟空英文书籍:美生中国人等
- 《荒野大镖客》PC版曝光!《GTA6》疑似也有PC版
- 林宥嘉.2008-神秘嘉宾(引进版)【华研国际】【WAV+CUE】
- 徐小凤.1997-金曲精选(康艺经典珍藏系列)【康艺成音】【WAV+CUE】
- 群星.1994-非常精丫宝丽金】【WAV+CUE】
- 《赛马娘 热血喧闹大感谢祭!》评测:现代复古派对
- 《星球大战:亡命之徒》评测:还是看看远方的光剑吧