{"id":1294,"date":"2024-05-31T08:38:36","date_gmt":"2024-05-31T00:38:36","guid":{"rendered":"http:\/\/ericw.top\/?p=1294"},"modified":"2024-05-31T08:39:27","modified_gmt":"2024-05-31T00:39:27","slug":"vueuse-%e5%9f%ba%e4%ba%8evue%e7%bb%84%e5%90%88%e5%bc%8fapi%e7%9a%84%e5%ae%9e%e7%94%a8%e5%b7%a5%e5%85%b7%e9%9b%86","status":"publish","type":"post","link":"http:\/\/ericw.top\/?p=1294","title":{"rendered":"VueUse \u57fa\u4e8eVue\u7ec4\u5408\u5f0fAPI\u7684\u5b9e\u7528\u5de5\u5177\u96c6"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large is-resized\"><img decoding=\"async\" width=\"1024\" height=\"610\" src=\"http:\/\/ericw.top\/wp-content\/uploads\/2024\/05\/image-4-1024x610.png\" alt=\"\" class=\"wp-image-1295\" style=\"width:494px;height:auto\" srcset=\"http:\/\/ericw.top\/wp-content\/uploads\/2024\/05\/image-4-1024x610.png 1024w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/05\/image-4-300x179.png 300w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/05\/image-4-768x458.png 768w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/05\/image-4.png 1170w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><a href=\"https:\/\/www.vueusejs.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">VueUse\u4e2d\u6587\u6587\u6863<\/a><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"516\" src=\"http:\/\/ericw.top\/wp-content\/uploads\/2024\/05\/image-5-1024x516.png\" alt=\"\" class=\"wp-image-1296\" srcset=\"http:\/\/ericw.top\/wp-content\/uploads\/2024\/05\/image-5-1024x516.png 1024w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/05\/image-5-300x151.png 300w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/05\/image-5-768x387.png 768w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/05\/image-5-1536x775.png 1536w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/05\/image-5-2048x1033.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc-0\"><strong>\u5b89\u88c5VueUse<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >npm i @vueuse\/core<\/code><\/pre>\n\n\n\n<p>VueUse\u91cc\u9762\u529f\u80fd\u975e\u5e38\u7684\u4e30\u5bcc\uff0c\u53ef\u80fd\u5e76\u4e0d\u662f\u6bcf\u4e00\u529f\u80fd\u51fd\u6570\u6211\u4eec\u90fd\u80fd\u7528\u5230\uff0c\u6240\u4ee5\u6211\u4eec\u7528\u5230\u54ea\u4e00\u4e2a\u529f\u80fd\u51fd\u6570\u5728\u7ec4\u4ef6\u4e2d\u6309\u9700\u5f15\u5165\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc-1\"><strong>useMouse\u2014\u2014\u83b7\u53d6\u9f20\u6807\u4f4d\u7f6e<\/strong><\/h2>\n\n\n\n<p><strong>useMouse<\/strong>\u662f\u4e00\u4e2a<strong>\u5b9e\u65f6\u76d1\u542c<\/strong>\u9f20\u6807\u4f4d\u7f6e\u53d8\u5316\u5e76\u8fd4\u56de\u5f53\u524d\u9f20\u6807\u4f4d\u7f6e\u5750\u6807x\uff0cy\u7684\u4e00\u4e2a\u65b9\u6cd5\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >export interface MouseOptions extends ConfigurableWindow {\r\n  \/\/ \u9f20\u6807\u7684\u4f4d\u7f6e\u662f\u76f8\u5bf9\u9875\u9762\u8fd8\u662f\u6d4f\u89c8\u5668\uff0c\u9ed8\u8ba4\u662f\u9875\u9762\r\n  type?: &quot;page&quot; | &quot;client&quot;\r\n \t\/\/ \u76d1\u542c `touchmove` \u4e8b\u4ef6\uff0c\u7528\u4e8e\u79fb\u52a8\u7aef\uff0c\u9ed8\u8ba4true\r\n  touch?: boolean\r\n \t\/\/ \u89e6\u53d1`touchend`\u4e8b\u4ef6\u65f6\u91cd\u7f6e\u4e3a\u521d\u59cb\u503c\uff0c\u9ed8\u8ba4false\r\n  resetOnTouchEnds?: boolean\r\n  \/\/ \u53ef\u4ee5\u8bbe\u7f6e\u521d\u59cb\u503c\r\n  initialValue?: Position\r\n}\r\n\/\/ \u6e90\u7c7b\u578b\u662f\u9f20\u6807\u8fd8\u89e6\u6478\r\nexport declare type MouseSourceType = &quot;mouse&quot; | &quot;touch&quot; | null\r\n\r\nexport declare function useMouse(options?: MouseOptions): {\r\n  x: Ref&lt;number&gt;\r\n  y: Ref&lt;number&gt;\r\n  sourceType: Ref&lt;MouseSourceType&gt;\r\n}\r\nexport declare type UseMouseReturn = ReturnType&lt;typeof useMouse&gt;\r\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >&lt;template&gt;\r\n    &lt;div&gt;\r\n        &lt;p&gt;x\u7684\u503c\uff1a{{ x }}&lt;\/p&gt;\r\n        &lt;p&gt;y\u7684\u503c\uff1a{{ y }}&lt;\/p&gt;\r\n    &lt;\/div&gt;\r\n&lt;\/template&gt;\r\n\r\n&lt;script lang=&quot;ts&quot; setup&gt;\r\n    import { useMouse } from &#039;@vueuse\/core&#039;;\r\n\r\n    const { x, y } = useMouse({\r\n        type: &#039;page&#039;,\r\n        touch: true,\r\n        resetOnTouchEnds: false,\r\n        initialValue: {\r\n            x: 100,\r\n            y: 200\r\n        }\r\n    })\r\n&lt;\/script&gt;\r\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc-2\"><strong>useDebounceFn\u2014\u2014\u9632\u6296<\/strong><\/h2>\n\n\n\n<p>\u5f53\u6301\u7eed\u89e6\u53d1\u4e8b\u4ef6\u65f6\uff0c\u4e00\u5b9a\u65f6\u95f4\u6bb5\u5185\u6ca1\u6709\u518d\u89e6\u53d1\u4e8b\u4ef6\uff0c\u4e8b\u4ef6\u5904\u7406\u51fd\u6570\u624d\u4f1a\u6267\u884c\u4e00\u6b21\uff0c\u5982\u679c\u8bbe\u5b9a\u7684\u65f6\u95f4\u5230\u6765\u4e4b\u524d\uff0c\u53c8\u4e00\u6b21\u89e6\u53d1\u4e86\u4e8b\u4ef6\uff0c\u5c31\u91cd\u65b0\u5f00\u59cb\u5ef6\u65f6\u3002<br><strong>(\u5f53\u7528\u6237\u591a\u6b21\u8fde\u7eed\u70b9\u51fb\u65f6\uff0c\u53ea\u4f1a\u8bc6\u522b\u4e00\u6b21\u5f97\u70b9\u51fb\u4e8b\u4ef6)<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >&lt;template&gt;\r\n    &lt;p&gt; {{ counter }}&lt;\/p&gt;\r\n\r\n    &lt;button @click=&quot;clickedFn&quot;&gt;UseDebounceFn&lt;\/button&gt;\r\n&lt;\/template&gt;\r\n\r\n&lt;script setup lang=&quot;ts&quot;&gt;\r\n    import { ref } from &#039;vue&#039;\r\n    import { useDebounceFn } from &#039;@vueuse\/core&#039;\r\n\r\n    const counter = ref(0)\r\n    \/\/ \u7b2c\u4e09\u4e2a\u53c2\u6570\u4e3a\u6700\u5927\u7b49\u5f85\u65f6\u95f4\uff0c\u7c7b\u4f3c\u4e8e lodash debounce\r\n    const debouncedFn = useDebounceFn(() =&gt; {\r\n        counter.value += 1\r\n    }, 1000, { maxWait: 5000 })\r\n\r\n    const clickedFn = () =&gt; {\r\n        debouncedFn()\r\n    }\r\n&lt;\/script&gt;\r\n<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>VueUse\u4e2d\u6587\u6587\u6863 \u5b89\u88c5VueUse VueUse\u91cc\u9762\u529f\u80fd\u975e\u5e38\u7684\u4e30\u5bcc\uff0c\u53ef\u80fd\u5e76\u4e0d\u662f\u6bcf\u4e00\u529f\u80fd\u51fd\u6570\u6211\u4eec\u90fd\u80fd\u7528\u5230\uff0c\u6240 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17,11,1],"tags":[],"_links":{"self":[{"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/posts\/1294"}],"collection":[{"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1294"}],"version-history":[{"count":1,"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/posts\/1294\/revisions"}],"predecessor-version":[{"id":1297,"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/posts\/1294\/revisions\/1297"}],"wp:attachment":[{"href":"http:\/\/ericw.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1294"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1294"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1294"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}