/** * @param {Number} time 传入需要等待时间的值 */ async function sleep(time) { return new Promise((resolve) => { setInterval(() => { resolve(); }, time); }); } async function test(){ console.log("测试") while(20--){ await sleep(1000) console.log(1++) } } test()