函数recursive 是异步加递归 理想状态是:在函数updateParams调用 await函数recursive执行完后再执行后面代码。 实际:函数recursive还没执行完后面的代码就执行了 * * * async updateParams(type, keyword) { if(this.treeData.length === 0) { await this.recursive(this.vNode.childNodes) console.log("🐇 updateParams this.recursive👻", this.treeData) } console.log('查找-'); const data = this.treeData.find(item => item.path === type) this.setParams(data) const query = Object.assign({}, this.params,{ current : 1, size : 10000, data : keyword }) const res = await fetchPage(query) this.ids = res.data.data.records.map(i => i.id) }, * * * async recursive(data) { try { for (let i = 0; i { if(!item.isLeaf) { const Arr = [item] this.recursive(Arr) } this.treeData.push(item) }); } } } catch (error) { console.log('获取树形数据失败',error); } console.log('数据收集完毕'); }, * * * getQueryParams(res) { const data = res.data ? res.data : res return { id: data.id, filter: data.filter || '', path: data.path || '', fondsCode: this.current_fonds } },