axios.all 并发响应回调如何能让其只触发一次?
问题如下:
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
}))
问问题经常说不明白,所以加张截图吧!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
造成多次请求的原因是你多次运行了getInfo函数,
that.getInfo()
,这个函数里面会重复发送axios请求,可以这么写这个地方直接就会把所有请求发出去,axios.get()直接就执行了啊