{"id":39426,"date":"2025-05-23T18:13:15","date_gmt":"2025-05-23T10:13:15","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/39426.html"},"modified":"2025-05-23T18:13:15","modified_gmt":"2025-05-23T10:13:15","slug":"vue-3-%e5%ae%98%e6%96%b9-hooks-%e7%9a%84%e7%94%a8%e6%b3%95%e4%b8%8e%e5%ae%9e%e7%8e%b0%e5%8e%9f%e7%90%86","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/39426.html","title":{"rendered":"Vue 3 \u5b98\u65b9 Hooks \u7684\u7528\u6cd5\u4e0e\u5b9e\u73b0\u539f\u7406"},"content":{"rendered":"<p>Vue 3 \u5f15\u5165\u4e86 Composition API&#xff0c;\u4f7f\u5f97\u751f\u547d\u5468\u671f\u94a9\u5b50&#xff08;hooks&#xff09;\u5728\u51fd\u6570\u5f0f\u98ce\u683c\u4e2d\u66f4\u6e05\u6670\u5730\u8868\u8fbe\u3002\u672c\u7bc7\u6587\u7ae0\u5c06\u4ece\u5b98\u65b9 hooks \u7684\u4f7f\u7528\u3001\u5b9e\u73b0\u539f\u7406\u4ee5\u53ca\u81ea\u5b9a\u4e49 hooks \u7684\u7ed3\u6784\u5316\u601d\u8def\u51fa\u53d1&#xff0c;\u5168\u9762\u7406\u89e3 Vue 3 \u7684 hooks \u7cfb\u7edf\u3002<\/p>\n<hr \/>\n<h3>&#x1f4d8; 1. Vue 3 \u5b98\u65b9\u751f\u547d\u5468\u671f hooks \u4e00\u89c8<\/h3>\n<table>\n<tr>Hook \u51fd\u6570\u89e6\u53d1\u65f6\u673a<\/tr>\n<tbody>\n<tr>\n<td>onBeforeMount<\/td>\n<td>\u7ec4\u4ef6\u6302\u8f7d\u524d<\/td>\n<\/tr>\n<tr>\n<td>onMounted<\/td>\n<td>\u7ec4\u4ef6\u6302\u8f7d\u540e<\/td>\n<\/tr>\n<tr>\n<td>onBeforeUpdate<\/td>\n<td>\u6570\u636e\u53d8\u66f4\u3001\u89c6\u56fe\u66f4\u65b0\u524d<\/td>\n<\/tr>\n<tr>\n<td>onUpdated<\/td>\n<td>\u6570\u636e\u53d8\u66f4\u3001\u89c6\u56fe\u66f4\u65b0\u540e<\/td>\n<\/tr>\n<tr>\n<td>onBeforeUnmount<\/td>\n<td>\u5378\u8f7d\u524d<\/td>\n<\/tr>\n<tr>\n<td>onUnmounted<\/td>\n<td>\u5378\u8f7d\u540e<\/td>\n<\/tr>\n<tr>\n<td>onActivated<\/td>\n<td>&lt;KeepAlive&gt; \u6fc0\u6d3b\u65f6<\/td>\n<\/tr>\n<tr>\n<td>onDeactivated<\/td>\n<td>&lt;KeepAlive&gt; \u5931\u6d3b\u65f6<\/td>\n<\/tr>\n<tr>\n<td>onErrorCaptured<\/td>\n<td>\u9519\u8bef\u6355\u83b7<\/td>\n<\/tr>\n<tr>\n<td>onRenderTracked<\/td>\n<td>\u54cd\u5e94\u5f0f\u4f9d\u8d56\u8ffd\u8e2a<\/td>\n<\/tr>\n<tr>\n<td>onRenderTriggered<\/td>\n<td>\u54cd\u5e94\u5f0f\u4f9d\u8d56\u89e6\u53d1\u66f4\u65b0<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h3>\u2705 2. \u4f7f\u7528\u793a\u4f8b<\/h3>\n<p><span class=\"token operator\">&lt;<\/span>script setup<span class=\"token operator\">&gt;<\/span><br \/>\n<span class=\"token keyword\">import<\/span> <span class=\"token punctuation\">{<\/span> onMounted <span class=\"token punctuation\">}<\/span> <span class=\"token keyword\">from<\/span> <span class=\"token string\">&#039;vue&#039;<\/span><\/p>\n<p><span class=\"token function\">onMounted<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#061;&gt;<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n  <span class=\"token builtin\">console<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">log<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;\u7ec4\u4ef6\u5df2\u6302\u8f7d\u5b8c\u6210&#039;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token operator\">&lt;<\/span><span class=\"token operator\">\/<\/span>script<span class=\"token operator\">&gt;<\/span><\/p>\n<p>\u5728 &lt;script setup&gt; \u4e2d\u8c03\u7528 hooks \u66f4\u7b80\u6d01&#xff0c;\u65e0\u9700\u8bbf\u95ee setup() \u8fd4\u56de\u5bf9\u8c61\u3002<\/p>\n<hr \/>\n<h3>&#x1f9e0; 3. \u5b9e\u73b0\u539f\u7406\u89e3\u6790<\/h3>\n<p>\u751f\u547d\u5468\u671f hooks \u7684\u6ce8\u518c\u57fa\u4e8e\u5f53\u524d\u7ec4\u4ef6\u5b9e\u4f8b currentInstance&#xff1a;<\/p>\n<p><span class=\"token keyword\">export<\/span> <span class=\"token keyword\">function<\/span> <span class=\"token function\">onMounted<\/span><span class=\"token punctuation\">(<\/span>hook<span class=\"token operator\">:<\/span> <span class=\"token builtin\">Function<\/span><span class=\"token punctuation\">,<\/span> target <span class=\"token operator\">&#061;<\/span> currentInstance<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n  <span class=\"token keyword\">return<\/span> <span class=\"token function\">injectHook<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;mounted&#039;<\/span><span class=\"token punctuation\">,<\/span> hook<span class=\"token punctuation\">,<\/span> target<span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u6838\u5fc3\u51fd\u6570 injectHook&#xff1a;<\/p>\n<p><span class=\"token keyword\">function<\/span> <span class=\"token function\">injectHook<\/span><span class=\"token punctuation\">(<\/span>type<span class=\"token operator\">:<\/span> LifecycleHooks<span class=\"token punctuation\">,<\/span> hook<span class=\"token operator\">:<\/span> <span class=\"token builtin\">Function<\/span><span class=\"token punctuation\">,<\/span> target<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n  <span class=\"token keyword\">const<\/span> hooks <span class=\"token operator\">&#061;<\/span> target<span class=\"token punctuation\">[<\/span>type<span class=\"token punctuation\">]<\/span> <span class=\"token operator\">||<\/span> <span class=\"token punctuation\">(<\/span>target<span class=\"token punctuation\">[<\/span>type<span class=\"token punctuation\">]<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span><br \/>\n  hooks<span class=\"token punctuation\">.<\/span><span class=\"token function\">push<\/span><span class=\"token punctuation\">(<\/span>hook<span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u5f53\u7ec4\u4ef6\u8fdb\u5165\u5bf9\u5e94\u751f\u547d\u5468\u671f\u9636\u6bb5\u65f6&#xff0c;Vue \u5185\u90e8\u4f1a\u904d\u5386\u6267\u884c\u6302\u8f7d\u5728\u5b9e\u4f8b\u4e0a\u7684\u6240\u6709\u8be5\u7c7b\u578b hook\u3002<\/p>\n<hr \/>\n<h3>\u267b\ufe0f 4. \u81ea\u5b9a\u4e49 Hooks&#xff08;\u7ec4\u5408\u903b\u8f91\u590d\u7528&#xff09;<\/h3>\n<p>Vue 3 \u9f13\u52b1\u5c06\u903b\u8f91\u62c6\u5206\u4e3a useXxx \u51fd\u6570&#xff0c;\u4ee5\u4fbf\u8de8\u7ec4\u4ef6\u590d\u7528\u3002<\/p>\n<h4>&#x1f3af; \u793a\u4f8b&#xff1a;useWindowSize<\/h4>\n<p><span class=\"token comment\">\/\/ useWindowSize.ts<\/span><br \/>\n<span class=\"token keyword\">import<\/span> <span class=\"token punctuation\">{<\/span> ref<span class=\"token punctuation\">,<\/span> onMounted<span class=\"token punctuation\">,<\/span> onUnmounted <span class=\"token punctuation\">}<\/span> <span class=\"token keyword\">from<\/span> <span class=\"token string\">&#039;vue&#039;<\/span><\/p>\n<p><span class=\"token keyword\">export<\/span> <span class=\"token keyword\">function<\/span> <span class=\"token function\">useWindowSize<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n  <span class=\"token keyword\">const<\/span> width <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">ref<\/span><span class=\"token punctuation\">(<\/span>window<span class=\"token punctuation\">.<\/span>innerWidth<span class=\"token punctuation\">)<\/span><br \/>\n  <span class=\"token keyword\">const<\/span> height <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">ref<\/span><span class=\"token punctuation\">(<\/span>window<span class=\"token punctuation\">.<\/span>innerHeight<span class=\"token punctuation\">)<\/span><\/p>\n<p>  <span class=\"token keyword\">const<\/span> <span class=\"token function-variable function\">update<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#061;&gt;<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    width<span class=\"token punctuation\">.<\/span>value <span class=\"token operator\">&#061;<\/span> window<span class=\"token punctuation\">.<\/span>innerWidth<br \/>\n    height<span class=\"token punctuation\">.<\/span>value <span class=\"token operator\">&#061;<\/span> window<span class=\"token punctuation\">.<\/span>innerHeight<br \/>\n  <span class=\"token punctuation\">}<\/span><\/p>\n<p>  <span class=\"token function\">onMounted<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#061;&gt;<\/span> window<span class=\"token punctuation\">.<\/span><span class=\"token function\">addEventListener<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;resize&#039;<\/span><span class=\"token punctuation\">,<\/span> update<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><br \/>\n  <span class=\"token function\">onUnmounted<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#061;&gt;<\/span> window<span class=\"token punctuation\">.<\/span><span class=\"token function\">removeEventListener<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;resize&#039;<\/span><span class=\"token punctuation\">,<\/span> update<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>  <span class=\"token keyword\">return<\/span> <span class=\"token punctuation\">{<\/span> width<span class=\"token punctuation\">,<\/span> height <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<h4>\u4f7f\u7528\u65b9\u5f0f&#xff1a;<\/h4>\n<p><span class=\"token operator\">&lt;<\/span>script setup<span class=\"token operator\">&gt;<\/span><br \/>\n<span class=\"token keyword\">import<\/span> <span class=\"token punctuation\">{<\/span> useWindowSize <span class=\"token punctuation\">}<\/span> <span class=\"token keyword\">from<\/span> <span class=\"token string\">&#039;&#064;\/hooks\/useWindowSize&#039;<\/span><\/p>\n<p><span class=\"token keyword\">const<\/span> <span class=\"token punctuation\">{<\/span> width<span class=\"token punctuation\">,<\/span> height <span class=\"token punctuation\">}<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token function\">useWindowSize<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token operator\">&lt;<\/span><span class=\"token operator\">\/<\/span>script<span class=\"token operator\">&gt;<\/span><\/p>\n<hr \/>\n<h3>&#x1f9e0; \u81ea\u5b9a\u4e49 hooks \u7684\u539f\u7406<\/h3>\n<ul>\n<li>\u672c\u8d28\u662f\u666e\u901a\u51fd\u6570&#xff0c;\u5185\u90e8\u8c03\u7528 Vue \u7ec4\u5408\u5f0f API&#xff08;\u5982 ref, watch, onMounted&#xff09;<\/li>\n<li>\u5728\u7ec4\u4ef6 setup() \u65f6\u6267\u884c&#xff0c;\u54cd\u5e94\u5f0f\u53d8\u91cf\u6302\u63a5\u5230\u5f53\u524d\u7ec4\u4ef6\u4e0a\u4e0b\u6587<\/li>\n<li>\u5185\u90e8\u8c03\u7528\u751f\u547d\u5468\u671f\u94a9\u5b50\u65f6\u4f1a\u4f9d\u8d56\u5f53\u524d\u7684 getCurrentInstance()<\/li>\n<\/ul>\n<hr \/>\n<h3>&#x1f4cc; 5. \u603b\u7ed3\u5bf9\u6bd4<\/h3>\n<table>\n<tr>\u7c7b\u578b\u793a\u4f8b\u4f5c\u7528\u7279\u70b9<\/tr>\n<tbody>\n<tr>\n<td>\u5b98\u65b9\u751f\u547d\u5468\u671f Hook<\/td>\n<td>onMounted()<\/td>\n<td>\u6ce8\u518c\u751f\u547d\u5468\u671f\u56de\u8c03<\/td>\n<td>\u7531 Vue \u5185\u90e8\u8c03\u5ea6<\/td>\n<\/tr>\n<tr>\n<td>\u81ea\u5b9a\u4e49 Hook<\/td>\n<td>useMousePosition()<\/td>\n<td>\u5c01\u88c5\u54cd\u5e94\u5f0f\u72b6\u6001 &#043; \u903b\u8f91\u590d\u7528<\/td>\n<td>\u662f\u666e\u901a\u51fd\u6570&#xff0c;\u53ef\u7ec4\u5408\u5d4c\u5957<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h3>&#x1f4da; \u63a8\u8350\u9605\u8bfb<\/h3>\n<ul>\n<li>Vue 3 \u5b98\u65b9\u751f\u547d\u5468\u671f API<\/li>\n<li>Vue \u6838\u5fc3\u6e90\u7801 Lifecycle \u5b9e\u73b0<\/li>\n<li>VueUse &#8211; \u9ad8\u8d28\u91cf Hooks \u96c6\u5408<\/li>\n<\/ul>\n<hr \/>\n<h3>\u270d\ufe0f \u7ed3\u8bed<\/h3>\n<p>\u751f\u547d\u5468\u671f hooks \u662f Vue 3 \u4e2d\u975e\u5e38\u6838\u5fc3\u7684\u673a\u5236\u4e4b\u4e00\u3002\u7406\u89e3\u5b83\u4eec\u7684\u7528\u6cd5\u4e0e\u5b9e\u73b0&#xff0c;\u6709\u52a9\u4e8e\u6211\u4eec\u7f16\u5199\u7ed3\u6784\u6e05\u6670\u3001\u903b\u8f91\u53ef\u590d\u7528\u7684\u7ec4\u4ef6\u3002<\/p>\n<p>\u5982\u679c\u4f60\u5bf9 Vue \u6e90\u7801\u611f\u5174\u8da3&#xff0c;\u4e0d\u59a8\u8fdb\u4e00\u6b65\u63a2\u7d22 Vue \u662f\u5982\u4f55\u4f9d\u8d56 currentInstance \u6765\u5904\u7406\u4f5c\u7528\u57df\u94a9\u5b50\u7684\u6ce8\u518c\u548c\u8c03\u7528\u7684\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb465\u6b21\uff0c\u70b9\u8d5e6\u6b21\uff0c\u6536\u85cf3\u6b21\u3002Vue 3 \u7684 Composition API \u5f15\u5165\u4e86\u751f\u547d\u5468\u671f\u94a9\u5b50\uff08hooks\uff09\uff0c\u4f7f\u5f97\u5728\u51fd\u6570\u5f0f\u98ce\u683c\u4e2d\u66f4\u6e05\u6670\u5730\u7ba1\u7406\u7ec4\u4ef6\u751f\u547d\u5468\u671f\u3002\u672c\u6587\u8be6\u7ec6\u4ecb\u7ecd\u4e86\u5b98\u65b9\u751f\u547d\u5468\u671f hooks \u7684\u4f7f\u7528\u3001\u5b9e\u73b0\u539f\u7406\u4ee5\u53ca\u5982\u4f55\u81ea\u5b9a\u4e49 hooks\u3002<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[187,1205,458,625,87],"topic":[],"class_list":["post-39426","post","type-post","status-publish","format-standard","hentry","category-server","tag-javascript","tag-js","tag-vue","tag-vue-js","tag-87"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Vue 3 \u5b98\u65b9 Hooks \u7684\u7528\u6cd5\u4e0e\u5b9e\u73b0\u539f\u7406 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/39426.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Vue 3 \u5b98\u65b9 Hooks \u7684\u7528\u6cd5\u4e0e\u5b9e\u73b0\u539f\u7406 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb465\u6b21\uff0c\u70b9\u8d5e6\u6b21\uff0c\u6536\u85cf3\u6b21\u3002Vue 3 \u7684 Composition API \u5f15\u5165\u4e86\u751f\u547d\u5468\u671f\u94a9\u5b50\uff08hooks\uff09\uff0c\u4f7f\u5f97\u5728\u51fd\u6570\u5f0f\u98ce\u683c\u4e2d\u66f4\u6e05\u6670\u5730\u7ba1\u7406\u7ec4\u4ef6\u751f\u547d\u5468\u671f\u3002\u672c\u6587\u8be6\u7ec6\u4ecb\u7ecd\u4e86\u5b98\u65b9\u751f\u547d\u5468\u671f hooks \u7684\u4f7f\u7528\u3001\u5b9e\u73b0\u539f\u7406\u4ee5\u53ca\u5982\u4f55\u81ea\u5b9a\u4e49 hooks\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/39426.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-05-23T10:13:15+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/39426.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/39426.html\",\"name\":\"Vue 3 \u5b98\u65b9 Hooks \u7684\u7528\u6cd5\u4e0e\u5b9e\u73b0\u539f\u7406 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-05-23T10:13:15+00:00\",\"dateModified\":\"2025-05-23T10:13:15+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/39426.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/39426.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/39426.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Vue 3 \u5b98\u65b9 Hooks \u7684\u7528\u6cd5\u4e0e\u5b9e\u73b0\u539f\u7406\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Vue 3 \u5b98\u65b9 Hooks \u7684\u7528\u6cd5\u4e0e\u5b9e\u73b0\u539f\u7406 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/39426.html","og_locale":"zh_CN","og_type":"article","og_title":"Vue 3 \u5b98\u65b9 Hooks \u7684\u7528\u6cd5\u4e0e\u5b9e\u73b0\u539f\u7406 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb465\u6b21\uff0c\u70b9\u8d5e6\u6b21\uff0c\u6536\u85cf3\u6b21\u3002Vue 3 \u7684 Composition API \u5f15\u5165\u4e86\u751f\u547d\u5468\u671f\u94a9\u5b50\uff08hooks\uff09\uff0c\u4f7f\u5f97\u5728\u51fd\u6570\u5f0f\u98ce\u683c\u4e2d\u66f4\u6e05\u6670\u5730\u7ba1\u7406\u7ec4\u4ef6\u751f\u547d\u5468\u671f\u3002\u672c\u6587\u8be6\u7ec6\u4ecb\u7ecd\u4e86\u5b98\u65b9\u751f\u547d\u5468\u671f hooks \u7684\u4f7f\u7528\u3001\u5b9e\u73b0\u539f\u7406\u4ee5\u53ca\u5982\u4f55\u81ea\u5b9a\u4e49 hooks\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/39426.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-05-23T10:13:15+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"1 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/39426.html","url":"https:\/\/www.wsisp.com\/helps\/39426.html","name":"Vue 3 \u5b98\u65b9 Hooks \u7684\u7528\u6cd5\u4e0e\u5b9e\u73b0\u539f\u7406 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-05-23T10:13:15+00:00","dateModified":"2025-05-23T10:13:15+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/39426.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/39426.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/39426.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Vue 3 \u5b98\u65b9 Hooks \u7684\u7528\u6cd5\u4e0e\u5b9e\u73b0\u539f\u7406"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/39426","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=39426"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/39426\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=39426"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=39426"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=39426"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=39426"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}