/*! For license information please see 3255.da4ce46b.js.LICENSE.txt */ (self.webpackChunk=self.webpackChunk||[]).push([["3255"],{64250:function(s,n,a){"use strict";a.r(n);var l=a("80681");let e=["innerHTML"];n.default={setup:()=>({html:""}),render:()=>((0,l.wg)(),(0,l.iD)("div",{class:"van-doc-markdown-body",innerHTML:'

useRaf

\n

Intro

\n

Provide convenient call and cancellation of requestAnimationFrame.

\n

Usage

\n

Single Call

\n

By using the useRaf method, you can execute a function before the next browser repaint.

\n
import { useRaf } from '@vant/use';\n\nexport default {\n  setup() {\n    let count = 0;\n    useRaf(() => {\n      console.log(++count); // It will only be executed once.\n    });\n  },\n};\n
\n

Loop Calls

\n

By using the isLoop option, you can execution of a function repeatedly at a specified interval until it is canceled.

\n
import { useRaf } from '@vant/use';\n\nexport default {\n  setup() {\n    let count = 0;\n    const cancelRaf = useRaf(\n      () => {\n        console.log(++count); // Execute infinitely until canceled\n\n        if (count === 5) {\n          cancelRaf();\n        }\n      },\n      {\n        isLoop: true, // Enable the loop\n        interval: 100, // Set call interval\n      },\n    );\n  },\n};\n
\n

API

\n

Type Declarations

\n
function useRaf(\n  callback: () => void,\n  options: {\n    interval?: number;\n    isLoop?: boolean;\n  },\n): void;\n
\n

Params

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
NameDescriptionTypeDefault
callbackCallback() => void-
optionsOptions{ interval?: number; isLoop?: boolean }{ interval: 0; isLoop: false }
\n
'},null,8,e))}}}]);