久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

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

解決vue 使用axios.all()方法發(fā)起多個(gè)請(qǐng)求控制臺(tái)報(bào)錯(cuò)的問題

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

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

解決vue 使用axios.all()方法發(fā)起多個(gè)請(qǐng)求控制臺(tái)報(bào)錯(cuò)的問題

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

instance.all = axios.all

就完美解決了!

補(bǔ)充知識(shí):vue項(xiàng)目中使用axios.all處理并發(fā)請(qǐng)求報(bào)_util2.default.axios.all is not a function異常

報(bào)錯(cuò):

_util2.default.axios.all is not a function

代碼:

init () { util.axios.all([this.getCourseInit(), this.getConfirmInit()]).then(util.axios.spread((indexRes, confirmRes) => { // 兩個(gè)請(qǐng)求現(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實(shí)例沒有all這個(gè)方法,all是axios的靜態(tài)方法

解決辦法:

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

// 引入axios import axios from ’axios’; init () { axios.all([this.getCourseInit(), this.getConfirmInit()]).then(axios.spread((indexRes, confirmRes) => { // 兩個(gè)請(qǐng)求現(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ā)起多個(gè)請(qǐng)求控制臺(tái)報(bào)錯(cuò)的問題就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: IOS
相關(guān)文章:
主站蜘蛛池模板: 五台县| 宜兰市| 水城县| 永福县| 扎兰屯市| 安溪县| 广安市| 鄱阳县| 平利县| 东明县| 长寿区| 凉城县| 宝丰县| 红安县| 洛宁县| 云阳县| 合川市| 莎车县| 昌图县| 丰城市| 东乌| 东山县| 龙里县| 阳信县| 得荣县| 安泽县| 罗江县| 毕节市| 邢台县| 崇义县| 广宁县| 永宁县| 溆浦县| 宽城| 资溪县| 克拉玛依市| 张家港市| 北海市| 雷山县| 安仁县| 贡嘎县|