跳转到主要内容

同步API Sync API

为确保您的代码在RevIQ脚本加载完成后执行,您可以使用 reviq 命令队列。 To ensure that your code runs after the RevIQ script is loaded, you can use the reviq command queue.
RevIQ脚本采用异步加载方式,以避免阻塞页面渲染。请务必确认API已就绪后再进行调用。 The RevIQ script loads asynchronously in order to not block the page. It’s important to make sure that the API is ready before you call it.
index.js
globalThis.reviq = globalThis.reviq || [];
reviq.push((reviq) => {
    // 在此编写您的代码 Your code here
    reviq.setKv('foo', 'bar');
});
您也可以创建一个Promise,在首次调用 reviq 命令后resolve。 Alternatively, you can create a Promise that resolves after the first reviq command is called.
index.js
const reviqReady = new Promise((resolve) => {
  reviq = reviq || [];
  reviq.push((reviq) => {
    resolve(reviq);
  });
});
async function doSetKv() {
  const reviq = await reviqReady;
  reviq.setKv("foo", "bar");
}