久久福利_99r_国产日韩在线视频_直接看av的网站_中文欧美日韩_久久一

您的位置:首頁技術(shù)文章
文章詳情頁

解決vue 使用axios.all()方法發(fā)起多個請求控制臺報錯的問題

瀏覽:4日期:2022-11-03 16:41:34

今天在項目中使用axios時發(fā)現(xiàn)axios.all() 方法可以執(zhí)行但是控制臺報錯,后來在論壇中看到是由于axios.all() 方法并沒有掛載到 axios對象上,需要我們手動去添加

解決vue 使用axios.all()方法發(fā)起多個請求控制臺報錯的問題

== 只需要在你封裝的axios文件里加入 ==

instance.all = axios.all

就完美解決了!

補充知識:vue項目中使用axios.all處理并發(fā)請求報_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) => { // 兩個請求現(xiàn)在都執(zhí)行完成 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的靜態(tài)方法

解決辦法:

以下方法不是最好的,還沒找到更好的解決辦法,目前先這樣解決。

// 引入axios import axios from ’axios’; init () { axios.all([this.getCourseInit(), this.getConfirmInit()]).then(axios.spread((indexRes, confirmRes) => { // 兩個請求現(xiàn)在都執(zhí)行完成 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()方法發(fā)起多個請求控制臺報錯的問題就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: IOS
相關(guān)文章:
主站蜘蛛池模板: 国产女人和拘做受在线视频 | 久在草视频 | 日韩精品中文字幕在线观看 | 美女一区二区三区在线观看 | 成人练习生 | 九色91| 躁躁躁日躁夜夜躁 | 狠狠操狠狠操 | 538在线精品 | 久久久久久毛片免费播放 | 九九99九九精彩46 | 国产最好的精华液网站 | 日本一区二区三区免费观看 | 国产亚洲网站 | 午夜tv | 日韩美女av在线 | 日本视频中文字幕 | 国产日产精品一区二区三区四区 | 国产欧美综合在线 | 国产精品精品视频一区二区三区 | 久热中文字幕 | 亚洲男人天堂网 | 欧美一区二区免费 | 精品久久久久久久久久久 | 久久久久一区二区 | 亚洲第一视频 | 永久精品 | 福利网站在线观看 | 99国产精品| 国产一区二区在线免费观看 | 中文无码久久精品 | 美女福利网站 | 中文字幕一区二区三区四区不卡 | 日韩av网页 | 一区二区久久 | 欧美精品第一页 | 成人毛片视频网站 | 国产一区二区高潮 | 国产一区二区av | 成人二区| 得得啪在线视频 |