首先你需要知道 promise 要用then接收或者async await

例如:a() 是一个Promise封装的方法


// 定义一个变量直接a() 赋值给 b
let b = this.a()
console.log(b)  //这里就会返回 Promise {<pending>}

第一种方式 then 接收


let b = this.a()
.then(res =>{
	//.then是接收正确返回的信息
	console.log(res) // {...}
})
.catch(err =>{
	// .catch 返回报错信息
	console.log(err)
})

第二种方式 async await接收:


async c(){
	let b = await this.a()
	console.log(b)  // 现在就是正确返回了 {...}
	
}

这里要注意的是 async 和 await 必须是一起的

—————————————————————

小白上路,请多指教!!

Logo

基于 Vue 的企业级 UI 组件库和中后台系统解决方案,为数万开发者服务。

更多推荐