mounted() {
Promise.all([
getUserMenuList().then(response => { //第一個接口
return _.flatten(_.map(response || [], item => item.list || [])) //平展每一個response.list
})
starCount() //第二個接口
]).then(([gnmks,gnpfs]) => { //promise.all裏面全部的東西執行完了纔會進入then方法,then裏面兩個參數第一個是第一個接口的結果,第二個是第二個接口的結果
console.log(gnmks, gnpfs) //第一個接口的結果,第二個接口的結果
_.each(gnmks || [], item => {
if (item.url === '') {
const len = this.funcModule.push({gnmk:item.name,xjpf: 5, pfcs: 1}) //funcModule是定義的數組
_.each(gnpfs || [], value => {
if (item.name === value.gnmk ) {
_.extend(this.funcModule[len - 1], value) //數組合並
}
})
}
})
})
}複製代碼
用到了loadsh工具箱數組