axios.all 并发多次发起请求?

getInfo(){


    var that = this

    

    let obj = {

        banner: axios.get(that.url + 'home.php?Action=banner&setaction=banner'),

        logo: axios.get(that.url + 'home.php?Action=advertising&setaction=logo'),

        code: axios.get(that.url + 'home.php?Action=advertising&setaction=code'),

        himg: axios.get(that.url + 'home.php?Action=advertising&setaction=himg'),

        link: axios.get(that.url + 'home.php?Action=infolist&QType=link'),

        qq: axios.get(that.url + 'home.php?Action=infocontent&setaction=qq'),

        mail: axios.get(that.url + 'home.php?Action=infocontent&setaction=mail'),

        phone: axios.get(that.url + 'home.php?Action=infocontent&setaction=phone'),

        Hotline: axios.get(that.url + 'home.php?Action=infocontent&setaction=Hotline')

    }

    

    return obj

    }

var that = this


    axios.all([that.getInfo().banner, that.getInfo().logo, that.getInfo().code,

        that.getInfo().himg, that.getInfo().link, that.getInfo().qq, that.getInfo().mail,

        that.getInfo().phone, that.getInfo().Hotline

    ])

    .then(axios.spread(function(banner,logo,code,himg,link,qq,mail,phone,Hotline){

        that.banner = banner.data

        var swiper1 = new Swiper('.banners', {

            pagination: {

                el: '.swiper-pagination',

            },

            autoplay: true,

            speed: 800,

            observer:true,

        });

        that.logo = logo.data.photo

        that.code = code.data.photo

        that.htxtimg = himg.data.photo

        that.link = link.data

        that.qq = qq.data.Content

        console.log(qq);

        that.mail = mail.data.Content

        that.phone = phone.data.Content

        that.Hotline = Hotline.data.Content

    }))

https://img3.mukewang.com/5c99e4350001b52008000371.jpg

如图,axios.all()里面有多少个,就会请求少次,不是同时一齐只发一次...
各路大神有没什么解决方案,或是拆开一个一个发?

一只萌萌小番薯
浏览 1199回答 5
5回答

德玛西亚99

请求是在getInfo里一起发的啊

jeck猫

axios.all()的目的是批量发送请求,等所有请求都有返回时,再执行统一的回调,并不是把所有的请求合并成同一个请求发送

慕运维8079593

你把接口写成多个,又妄想axios给你合并到一起!axios库的功能没弄清楚吧

白衣染霜花

你接口设计的问题吧。axios不会合并请求,你有多少个请求它就会发出多少个请求,对于浏览器来说一次可以发出的请求是有上限的,对于ajax来说,任何的请求都会有一个等待的过程(或多或少)。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript