vant/static/js/async/1515.3b17635b.js
2024-04-20 08:49:23 +00:00

2 lines
4.4 KiB
JavaScript

/*! For license information please see 1515.3b17635b.js.LICENSE.txt */
(self.webpackChunk=self.webpackChunk||[]).push([["1515"],{57307:function(s,n,a){"use strict";a.r(n);var l=a("80681");let t=["innerHTML"];n.default={setup:()=>({html:""}),render:()=>((0,l.wg)(),(0,l.iD)("div",{class:"van-doc-markdown-body",innerHTML:'<h1>useRaf</h1>\n<div class="van-doc-card"><h3 id="jie-shao" tabindex="-1">\u4ECB\u7ECD</h3>\n<p>\u63D0\u4F9B\u4FBF\u6377\u7684 <a href="https://developer.mozilla.org/zh-CN/docs/Web/API/window/requestAnimationFrame" target="_blank">requestAnimationFrame</a> \u7684\u8C03\u7528\u548C\u53D6\u6D88\u3002</p>\n</div><h2 id="dai-ma-yan-shi" tabindex="-1">\u4EE3\u7801\u6F14\u793A</h2>\n<div class="van-doc-card"><h3 id="dan-ci-diao-yong" tabindex="-1">\u5355\u6B21\u8C03\u7528</h3>\n<p>\u901A\u8FC7 <code>useRaf</code> \u65B9\u6CD5\uFF0C\u53EF\u4EE5\u5728\u4E0B\u4E00\u6B21\u6D4F\u89C8\u5668\u91CD\u65B0\u7ED8\u5236\u4E4B\u524D\u8C03\u7528\u6307\u5B9A\u7684\u51FD\u6570\u3002</p>\n<pre><code class="language-js"><span class="hljs-keyword">import</span> { useRaf } <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;@vant/use&#x27;</span>;\n\n<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> {\n <span class="hljs-title function_">setup</span>(<span class="hljs-params"></span>) {\n <span class="hljs-keyword">let</span> count = <span class="hljs-number">0</span>;\n <span class="hljs-title function_">useRaf</span>(<span class="hljs-function">() =&gt;</span> {\n <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(++count); <span class="hljs-comment">// \u53EA\u4F1A\u6267\u884C 1 \u6B21</span>\n });\n },\n};\n</code></pre>\n</div><div class="van-doc-card"><h3 id="xun-huan-diao-yong" tabindex="-1">\u5FAA\u73AF\u8C03\u7528</h3>\n<p>\u901A\u8FC7\u5F00\u542F <code>isLoop</code> \u9009\u9879\uFF0C\u4F60\u53EF\u4EE5\u6309\u6307\u5B9A\u7684\u95F4\u9694\u91CD\u590D\u6267\u884C\u67D0\u4E2A\u51FD\u6570\uFF0C\u76F4\u5230\u88AB\u53D6\u6D88\u3002</p>\n<pre><code class="language-js"><span class="hljs-keyword">import</span> { useRaf } <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;@vant/use&#x27;</span>;\n\n<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> {\n <span class="hljs-title function_">setup</span>(<span class="hljs-params"></span>) {\n <span class="hljs-keyword">let</span> count = <span class="hljs-number">0</span>;\n <span class="hljs-keyword">const</span> cancelRaf = <span class="hljs-title function_">useRaf</span>(\n <span class="hljs-function">() =&gt;</span> {\n <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(++count); <span class="hljs-comment">// \u65E0\u9650\u6267\u884C\uFF0C\u76F4\u5230\u88AB cancel</span>\n\n <span class="hljs-keyword">if</span> (count === <span class="hljs-number">5</span>) {\n <span class="hljs-title function_">cancelRaf</span>();\n }\n },\n {\n <span class="hljs-attr">isLoop</span>: <span class="hljs-literal">true</span>, <span class="hljs-comment">// \u5F00\u542F\u5FAA\u73AF</span>\n <span class="hljs-attr">interval</span>: <span class="hljs-number">100</span>, <span class="hljs-comment">// \u8BBE\u7F6E\u8C03\u7528\u95F4\u9694</span>\n },\n );\n },\n};\n</code></pre>\n</div><h2 id="api" tabindex="-1">API</h2>\n<div class="van-doc-card"><h3 id="lei-xing-ding-yi" tabindex="-1">\u7C7B\u578B\u5B9A\u4E49</h3>\n<pre><code class="language-ts"><span class="hljs-keyword">function</span> <span class="hljs-title function_">useRaf</span>(<span class="hljs-params">\n callback: () =&gt; <span class="hljs-built_in">void</span>,\n options: {\n interval?: <span class="hljs-built_in">number</span>;\n isLoop?: <span class="hljs-built_in">boolean</span>;\n },\n</span>): <span class="hljs-built_in">void</span>;\n</code></pre>\n</div><div class="van-doc-card"><h3 id="can-shu" tabindex="-1">\u53C2\u6570</h3>\n<table>\n<thead>\n<tr>\n<th>\u53C2\u6570</th>\n<th>\u8BF4\u660E</th>\n<th>\u7C7B\u578B</th>\n<th>\u9ED8\u8BA4</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>callback</td>\n<td>\u56DE\u8C03\u51FD\u6570</td>\n<td><em>() =&gt; void</em></td>\n<td>-</td>\n</tr>\n<tr>\n<td>options</td>\n<td>\u914D\u7F6E\u53C2\u6570</td>\n<td><em>{ interval?: number; isLoop?: boolean }</em></td>\n<td><em>{ interval: 0; isLoop: false }</em></td>\n</tr>\n</tbody>\n</table>\n</div>'},null,8,t))}}}]);