3 回答

TA貢獻1829條經(jīng)驗 獲得超9個贊
您可以使用.then或獲得它await。
let valid = validateForm();
valid.then(function(valid) {
if (valid) {
}
})
async function submit () {
const valid = await validateForm();
if (valid) {
}
}
``

TA貢獻1818條經(jīng)驗 獲得超7個贊
使用then或await:
function promiseExample (){
return new Promise((resolve, reject)=> resolve("hello world"))
}
(async () => {
//with then
promiseExample()
.then(data => console.log('with then: ', data))
//with await
var data = await promiseExample()
console.log('with await: ', data);
})()

TA貢獻1770條經(jīng)驗 獲得超3個贊
很難相信一個簡單的谷歌搜索沒有給你答案,但這里有:
validateForm().then(value => console.log(value))
或者,在異步函數(shù)中:
let value = await validateForm();
添加回答
舉報