/*! 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:'
Provide convenient call and cancellation of requestAnimationFrame.
\nBy using the useRaf
method, you can execute a function before the next browser repaint.
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
\nBy using the isLoop
option, you can execution of a function repeatedly at a specified interval until it is canceled.
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
\nfunction useRaf(\n callback: () => void,\n options: {\n interval?: number;\n isLoop?: boolean;\n },\n): void;\n
\nName | \nDescription | \nType | \nDefault | \n
---|---|---|---|
callback | \nCallback | \n() => void | \n- | \n
options | \nOptions | \n{ interval?: number; isLoop?: boolean } | \n{ interval: 0; isLoop: false } | \n