国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

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

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

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

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

== 只需要在你封裝的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()方法發起多個請求控制臺報錯的問題就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持好吧啦網。

標簽: IOS
相關文章:
主站蜘蛛池模板: 寻乌县| 长岭县| 三江| 临湘市| 杨浦区| 焉耆| 杂多县| 桃园县| 烟台市| 湘西| 浦江县| 铁力市| 彭山县| 兖州市| 莲花县| 达日县| 蓬莱市| 平阳县| 广平县| 綦江县| 金门县| 大名县| 罗源县| 治多县| 千阳县| 东乡| 郧西县| 都江堰市| 蓝山县| 天等县| 康马县| 江安县| 濮阳县| 章丘市| 榆树市| 连山| 绥中县| 岗巴县| 赣州市| 东乌| 赤峰市|