引入
ts
import { nextTick } from 't-comm';
// 不支持 tree-shaking 的项目
import { nextTick} from 't-comm/lib/next-tick/index';
// 只支持 ESM 的项目
import { nextTick} from 't-comm/es/next-tick/index';nextTick
描述:
延迟执行函数,等待下一个渲染帧 使用 setTimeout 延迟 33ms(约一帧的时间),返回 Promise
参数:
返回: Promise.<number>
- 返回 Promise,resolve 值为 1
示例
ts
// 等待下一帧执行
await nextTick();
console.log('下一帧执行');
// 或使用 then
nextTick().then(() => {
console.log('下一帧执行');
});