关于promise实现同步
import React, {useEffect} from 'react'
const getDetails = function (call) {
// 发送一个get请求 jquery
$.get('/接口地址').done(res => {
call(res)
})
}
const App = () => {
const test = () => {
return new Promise((re, rej) => {
// bdata 返回数据
getDetails(bdata => {
re(bdata)
rej(bdata)
})
})
}
const getTestData = async () => {
// const res = await getDetails(() => {})
const res = await test()
console.log(res)
}
useEffect(() => {
getTestData()
}, [])
return (
<div>ceshi</div>
)
}
export default App