export default {
props: {},
data() {
return {}
},
computed: {},
components: {},
methods: {
// 接口一
async test1() {
let res = await this.$apis.getRiskAssessList()
return new Promise((resolve, reject) => {
if (res.code === 1) {
resolve(res.data)
} else {
reject(res.message)
}
})
},
// 接口二
async test2() {
let res = await this.$apis.fkConsultingCenterList()
return new Promise((resolve, reject) => {
if (res.code === 1) {
resolve(res.data)
} else {
reject(res.message)
}
})
},
// 统一调用接口
initList1() {
// Promise.all 「谁跑的慢,以谁为准执行回调」
// Promise.race 「谁跑的快,以谁为准执行回调」
Promise.all([this.test1(), this.test2()])
.then(res => {
console.log('res', res)
})
.catch(e => {
console.log(e)
})
},
// 按顺序执行
async initList2() {
let res2 = await this.test2()
console.log('res2', res2)
let res1 = await this.test1()
console.log('res1', res1)
}
},
mounted() {
this.initList1()
this.initList2()
},
watch: {}
}
版权声明:本文为wangyl1995原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。