{"id":52657,"date":"2024-12-03T15:32:34","date_gmt":"2024-12-03T07:32:34","guid":{"rendered":"https:\/\/fwq.ai\/blog\/52657\/"},"modified":"2024-12-03T15:32:34","modified_gmt":"2024-12-03T07:32:34","slug":"vue3-%e4%b8%ad-onload-%e6%96%b9%e6%b3%95%e5%a4%b1%e6%95%88%e6%80%8e%e4%b9%88%e5%8a%9e%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/52657\/","title":{"rendered":"Vue3 \u4e2d onload \u65b9\u6cd5\u5931\u6548\u600e\u4e48\u529e\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>Vue3 \u4e2d onload \u65b9\u6cd5\u5931\u6548\u600e\u4e48\u529e\uff1f<\/h1>\n<p>\u5728IT\u884c\u4e1a\u8fd9\u4e2a\u53d1\u5c55\u66f4\u65b0\u901f\u5ea6\u5f88\u5feb\u7684\u884c\u4e1a\uff0c\u53ea\u6709\u4e0d\u505c\u6b62\u7684\u5b66\u4e60\uff0c\u624d\u4e0d\u4f1a\u88ab\u884c\u4e1a\u6240\u6dd8\u6c70\u3002\u5982\u679c\u4f60\u662f\u6587\u7ae0\u5b66\u4e60\u8005\uff0c\u90a3\u4e48\u672c\u6587\u300aVue3 \u4e2d onload \u65b9\u6cd5\u5931\u6548\u600e\u4e48\u529e\uff1f\u300b\u5c31\u5f88\u9002\u5408\u4f60\uff01\u672c\u7bc7\u5185\u5bb9\u4e3b\u8981\u5305\u62ec##content_title##\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241122\/173225468367401bdb907b9.jpg\" class=\"aligncenter\" title=\"Vue3 \u4e2d onload \u65b9\u6cd5\u5931\u6548\u600e\u4e48\u529e\uff1f\u63d2\u56fe\" alt=\"Vue3 \u4e2d onload \u65b9\u6cd5\u5931\u6548\u600e\u4e48\u529e\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>vue3 \u4e2d onload \u65b9\u6cd5\u4e0d\u6267\u884c\u7684\u89e3\u51b3\u4e4b\u9053<\/strong><\/p>\n<p>\u5728 vue3 \u4e2d\uff0conload \u65b9\u6cd5\u65e0\u6cd5\u6b63\u5e38\u6267\u884c\u53ef\u80fd\u662f\u7531\u4e8e\u4ee5\u4e0b\u539f\u56e0\u9020\u6210\u7684\uff1a<\/p>\n<p><strong>\u539f\u56e0\uff1a<\/strong><\/p>\n<ul>\n<li>\u5c06 onload \u65b9\u6cd5\u5199\u5728 vue \u7ec4\u4ef6\u5185\uff0c\u800c\u4e0d\u662f\u5165\u53e3\u6587\u4ef6 (main.js) \u4e2d\u3002\u5728\u7ec4\u4ef6\u5185\uff0conload \u4e8b\u4ef6\u5df2\u5728\u65b9\u6cd5\u6267\u884c\u540e\u89e6\u53d1\u3002<\/li>\n<\/ul>\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><\/p>\n<p>\u4e3a\u4e86\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u9700\u8981\u5c06 onload \u65b9\u6cd5\u5199\u5728\u5165\u53e3\u6587\u4ef6 (main.js) \u4e2d\uff0c\u8fd9\u6837\u5b83\u624d\u80fd\u5728\u5e94\u7528\u7a0b\u5e8f\u542f\u52a8\u65f6\u6267\u884c\uff0c\u4ece\u800c\u786e\u4fdd\u9875\u9762\u5b8c\u5168\u52a0\u8f7d\u5b8c\u6210\u3002<\/p>\n<p><strong>\u4ee3\u7801\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>\/\/ main.js\n\nwindow.onload = () =&gt; {\n  console.log('loaded')\n}<\/pre>\n<p>\u6b64\u5916\uff0cvue \u7ec4\u4ef6\u4e2d\u65e0\u6cd5\u4f7f\u7528 onload \u65b9\u6cd5\uff0c\u4f46\u53ef\u4ee5\u4f7f\u7528 $nexttick \u65b9\u6cd5\u6765\u786e\u4fdd\u7ec4\u4ef6\u6302\u8f7d\u5b8c\u6210\u540e\u6267\u884c\u3002<\/p>\n<p><strong>\u4ee3\u7801\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>&lt;script&gt;\nonMounted(() =&gt; {\n  \/\/ \u7ec4\u4ef6\u6302\u8f7d\u5b8c\u6210\u540e\u6267\u884c\n  console.log('mounted')\n  nextTick(() =&gt; {\n    console.log('nextTick');\n  })\n})\n&lt;\/script&gt;<\/pre>\n<p>\u901a\u8fc7\u5c06 onload \u65b9\u6cd5\u79fb\u81f3\u5165\u53e3\u6587\u4ef6 (main.js) \u5e76\u4f7f\u7528 $nexttick \u65b9\u6cd5\uff0c\u4fbf\u53ef\u786e\u4fdd\u5728\u9875\u9762\u5b8c\u5168\u52a0\u8f7d\u5b8c\u6210\u540e\u6267\u884c\u6240\u9700\u7684\u64cd\u4f5c\uff0c\u4ece\u800c\u907f\u514d\u56e0\u80cc\u666f\u56fe\u5c1a\u672a\u6e32\u67d3\u5b8c\u6210\u800c\u5f71\u54cd\u5448\u73b0\u6548\u679c\u7684\u60c5\u51b5\u3002<\/p>\n<p>\u4eca\u5929\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u5e0c\u671b\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff1b\u5173\u4e8e\u6587\u7ae0\u7684\u6280\u672f\u77e5\u8bc6\u6211\u4eec\u4f1a\u4e00\u70b9\u70b9\u6df1\u5165\u4ecb\u7ecd\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff0c\u4e00\u8d77\u5b66\u4e60\u7f16\u7a0b~<\/p>\n<dl>\n<dt><\/dt>\n<dd>\n   \u627e\u5230\u6700\u8fd1\u7684\u56de\u6587\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>Vue3 \u4e2d onload \u65b9\u6cd5\u5931\u6548\u600e\u4e48\u529e\uff1f \u5728IT\u884c\u4e1a\u8fd9\u4e2a\u53d1\u5c55\u66f4\u65b0\u901f\u5ea6\u5f88\u5feb\u7684\u884c\u4e1a\uff0c\u53ea\u6709\u4e0d\u505c\u6b62\u7684\u5b66\u4e60\uff0c\u624d\u4e0d\u4f1a\u88ab\u884c\u4e1a\u6240\u6dd8\u6c70\u3002\u5982\u679c\u4f60\u662f\u6587\u7ae0\u5b66\u4e60\u8005\uff0c\u90a3\u4e48\u672c\u6587\u300aVue3 \u4e2d onload \u65b9\u6cd5\u5931\u6548\u600e\u4e48\u529e\uff1f\u300b\u5c31\u5f88\u9002\u5408\u4f60\uff01\u672c\u7bc7\u5185\u5bb9\u4e3b\u8981\u5305\u62ec##content_title##\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01 vue3 \u4e2d onload \u65b9\u6cd5\u4e0d\u6267\u884c\u7684\u89e3\u51b3\u4e4b\u9053 \u5728 vue3 \u4e2d\uff0conload \u65b9\u6cd5\u65e0\u6cd5\u6b63\u5e38\u6267\u884c\u53ef\u80fd\u662f\u7531\u4e8e\u4ee5\u4e0b\u539f\u56e0\u9020\u6210\u7684\uff1a \u539f\u56e0\uff1a \u5c06 onload \u65b9\u6cd5\u5199\u5728 vue \u7ec4\u4ef6\u5185\uff0c\u800c\u4e0d\u662f\u5165\u53e3\u6587\u4ef6 (main.js) \u4e2d\u3002\u5728\u7ec4\u4ef6\u5185\uff0conload \u4e8b\u4ef6\u5df2\u5728\u65b9\u6cd5\u6267\u884c\u540e\u89e6\u53d1\u3002 \u89e3\u51b3\u65b9\u6848\uff1a \u4e3a\u4e86\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u9700\u8981\u5c06 onload \u65b9\u6cd5\u5199\u5728\u5165\u53e3\u6587\u4ef6 (main.js) \u4e2d\uff0c\u8fd9\u6837\u5b83\u624d\u80fd\u5728\u5e94\u7528\u7a0b\u5e8f\u542f\u52a8\u65f6\u6267\u884c\uff0c\u4ece\u800c\u786e\u4fdd\u9875\u9762\u5b8c\u5168\u52a0\u8f7d\u5b8c\u6210\u3002 \u4ee3\u7801\u793a\u4f8b\uff1a \/\/ main.js window.onload = () =&gt; { console.log(&#8216;loaded&#8217;) } \u6b64\u5916\uff0cvue \u7ec4\u4ef6\u4e2d\u65e0\u6cd5\u4f7f\u7528 onload \u65b9\u6cd5\uff0c\u4f46\u53ef\u4ee5\u4f7f\u7528 $nexttick \u65b9\u6cd5\u6765\u786e\u4fdd\u7ec4\u4ef6\u6302\u8f7d\u5b8c\u6210\u540e\u6267\u884c\u3002 \u4ee3\u7801\u793a\u4f8b\uff1a &lt;script&gt; onMounted(() =&gt; { \/\/ \u7ec4\u4ef6\u6302\u8f7d\u5b8c\u6210\u540e\u6267\u884c console.log(&#8216;mounted&#8217;) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-52657","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52657","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=52657"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52657\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=52657"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=52657"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=52657"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}