专业的编程技术博客社区

网站首页 > 博客文章 正文

vue promise.all使用(vue promise用法)

baijin 2024-09-26 06:56:23 博客文章 3 ℃ 0 评论

1、问题:

一个页面可能有多个并发请求,我们想在所有请求完成后做处理,promise.all很好解决这个问题。

2、示例

3、结果

示例代码

created () {
 this.$toast.loading({
 duration: 0,
 forbidClick: true,
 loadingType: 'spinner'
 })
 },
 mounted () {
 this.init()
 },
 methods: {
 init () {
 Promise.all([
 this.$store.dispatch('getWeather', { city: '临沂', county: '兰山区' }),
 this.$store.dispatch('getWeather', { city: '临沂', county: '兰山区' }),
 new Promise((resolve, reject) => {
 setTimeout(() => {
 console.log(23456)
 resolve({})
 }, 3000)
 })
 ]).then(res => {
 this.$toast.clear()
 console.log(res)
 })
 }
 }

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表