{"id":5871,"date":"2025-06-10T09:12:36","date_gmt":"2025-06-17T02:12:35","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=5871"},"modified":"2025-06-17T09:12:36","modified_gmt":"2025-06-17T02:12:35","slug":"%e5%ad%b8%e7%bf%92%e5%a6%82%e4%bd%95%e5%9c%a8vue-js%e4%b8%ad%e4%bd%bf%e7%94%a8%e6%8f%92%e6%a7%bd","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/vue-js\/%e5%ad%b8%e7%bf%92%e5%a6%82%e4%bd%95%e5%9c%a8vue-js%e4%b8%ad%e4%bd%bf%e7%94%a8%e6%8f%92%e6%a7%bd\/","title":{"rendered":"2025 \u5e74\u6700\u65b0\uff1a\u5168\u9762\u5b78\u7fd2\u5982\u4f55\u5728 Vue.js \u4e2d\u4f7f\u7528\u63d2\u69fd"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"Vue.js, \u63d2\u69fd, \u7a0b\u5f0f\u7bc4\u4f8b, Vue 3, \u63d2\u69fd\u4f7f\u7528\"><\/p>\n<h1>\u5168\u9762\u5b78\u7fd2\u5982\u4f55\u5728 Vue.js \u4e2d\u4f7f\u7528\u63d2\u69fd<\/h1>\n<p>Vue.js \u662f\u4e00\u500b\u8f15\u91cf\u7d1a\u7684 JavaScript \u6846\u67b6\uff0c\u8b93\u958b\u767c\u8005\u80fd\u5920\u5feb\u901f\u958b\u767c\u51fa\u9ad8\u54c1\u8cea\u7684 Web \u61c9\u7528\u7a0b\u5f0f\u3002\u63d2\u69fd\uff08slot\uff09\u662f Vue.js \u4e2d\u4e00\u500b\u975e\u5e38\u5f37\u5927\u7684\u529f\u80fd\uff0c\u5141\u8a31\u958b\u767c\u8005\u5c07\u5143\u4ef6\u7684\u5167\u5bb9\u653e\u7f6e\u5728\u6307\u5b9a\u4f4d\u7f6e\uff0c\u5f9e\u800c\u63d0\u9ad8\u61c9\u7528\u7a0b\u5f0f\u7684\u53ef\u8b80\u6027\u548c\u53ef\u7dad\u8b77\u6027\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u5728 Vue.js \u4e2d\u4f7f\u7528\u63d2\u69fd\uff0c\u4ee5\u53ca\u63d2\u69fd\u7684\u57fa\u672c\u6982\u5ff5\uff0c\u4e26\u63d0\u4f9b 2025 \u5e74\u6700\u65b0\u7684\u8a9e\u6cd5\u8207\u6700\u4f73\u5be6\u8e10\u3002<\/p>\n<h2>\u4ec0\u9ebc\u662f\u63d2\u69fd\uff1f<\/h2>\n<p>\u63d2\u69fd\uff08slot\uff09\u662f Vue.js \u4e2d\u7684\u4e00\u500b\u529f\u80fd\uff0c\u5141\u8a31\u958b\u767c\u8005\u5728\u5143\u4ef6\u4e2d\u5b9a\u7fa9\u53ef\u66ff\u63db\u7684\u5167\u5bb9\u3002\u9019\u6a23\u4e00\u4f86\uff0c\u958b\u767c\u8005\u80fd\u5920\u9748\u6d3b\u5730\u5c07\u4e0d\u540c\u7684\u5167\u5bb9\u63d2\u5165\u5230\u5143\u4ef6\u4e2d\uff0c\u800c\u4e0d\u9700\u8981\u5c07\u9019\u4e9b\u5167\u5bb9\u5beb\u6b7b\u5728\u7a0b\u5f0f\u78bc\u4e2d\u3002\u63d2\u69fd\u662f\u5be6\u73fe\u5143\u4ef6\u7d44\u5408\u548c\u91cd\u7528\u7684\u91cd\u8981\u5de5\u5177\u3002<\/p>\n<h2>\u5982\u4f55\u5728 Vue.js \u4e2d\u4f7f\u7528\u63d2\u69fd\uff1f<\/h2>\n<p>\u5728 Vue.js \u4e2d\u4f7f\u7528\u63d2\u69fd\u7684\u65b9\u6cd5\u975e\u5e38\u7c21\u55ae\u3002\u4f60\u53ea\u9700\u8981\u5728\u5143\u4ef6\u7684\u6a21\u677f\u4e2d\u5b9a\u7fa9\u4e00\u500b `<slot>` \u6a19\u7c64\uff0c\u4e26\u5c07\u60f3\u8981\u63d2\u5165\u7684\u5167\u5bb9\u653e\u5728\u9019\u500b\u6a19\u7c64\u4e2d\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u7c21\u55ae\u7684\u5143\u4ef6\u7bc4\u4f8b\uff0c\u5b83\u5b9a\u7fa9\u4e86\u4e00\u500b `<slot>` \u6a19\u7c64\uff1a<\/p>\n<pre><code class=\"language-javascript\">\nVue.component('my-component', {\n  template: `\n    <div>\n      <h1>My Component<\/h1>\n      <slot><\/slot>\n    <\/div>\n  `\n})\n<\/code><\/pre>\n<p>\u5728\u4e0a\u9762\u7684\u7a0b\u5f0f\u78bc\u4e2d\uff0c\u6211\u5011\u5b9a\u7fa9\u4e86\u4e00\u500b\u540d\u70ba `my-component` \u7684\u5143\u4ef6\uff0c\u4e26\u5728\u5176\u6a21\u677f\u4e2d\u4f7f\u7528\u4e86 `<slot>` \u6a19\u7c64\u3002\u9019\u6a23\u4e00\u4f86\uff0c\u4efb\u4f55\u653e\u5165 `<my-component>` \u6a19\u7c64\u4e2d\u7684\u5167\u5bb9\u90fd\u6703\u986f\u793a\u5728 `<slot>` \u7684\u4f4d\u7f6e\u3002<\/p>\n<p>\u63a5\u4e0b\u4f86\uff0c\u6211\u5011\u53ef\u4ee5\u5728\u4f7f\u7528\u9019\u500b\u5143\u4ef6\u6642\u5c07\u4e0d\u540c\u7684\u5167\u5bb9\u653e\u5165\u63d2\u69fd\u4e2d\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre><code class=\"language-html\">\n<my-component>\n  <button>Click Me<\/button>\n<\/my-component>\n<\/code><\/pre>\n<p>\u5728\u9019\u500b\u7bc4\u4f8b\u4e2d\uff0c\u6309\u9215 &#8220;Click Me&#8221; \u5c07\u88ab\u63d2\u5165\u5230 `my-component` \u4e2d\u7684\u63d2\u69fd\u4f4d\u7f6e\u3002<\/p>\n<h2>\u4f7f\u7528\u5177\u540d\u63d2\u69fd<\/h2>\n<p>\u9664\u4e86\u57fa\u672c\u7684\u63d2\u69fd\uff0cVue.js \u9084\u652f\u6301\u5177\u540d\u63d2\u69fd\uff08named slots\uff09\uff0c\u9019\u4f7f\u5f97\u5143\u4ef6\u7684\u5167\u5bb9\u66f4\u5177\u9748\u6d3b\u6027\u3002\u4f60\u53ef\u4ee5\u70ba\u63d2\u69fd\u6307\u5b9a\u540d\u7a31\uff0c\u4e26\u5728\u4f7f\u7528\u5143\u4ef6\u6642\u586b\u5165\u5c0d\u61c9\u7684\u5167\u5bb9\u3002<\/p>\n<pre><code class=\"language-javascript\">\nVue.component('my-component', {\n  template: `\n    <div>\n      <h1>My Component<\/h1>\n      <slot name=\"header\"><\/slot>\n      <slot><\/slot>\n      <slot name=\"footer\"><\/slot>\n    <\/div>\n  `\n})\n<\/code><\/pre>\n<p>\u4f7f\u7528\u5177\u540d\u63d2\u69fd\u7684\u65b9\u5f0f\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-html\">\n<my-component>\n  <template v-slot:header>\n    <h2>This is the Header<\/h2>\n  <\/template>\n  \n  <p>This is the default content.<\/p>\n  \n  <template v-slot:footer>\n    <p>This is the Footer<\/p>\n  <\/template>\n<\/my-component>\n<\/code><\/pre>\n<p>\u5728\u9019\u500b\u7bc4\u4f8b\u4e2d\uff0c\u6211\u5011\u5b9a\u7fa9\u4e86\u4e09\u500b\u4e0d\u540c\u7684\u63d2\u69fd\uff1a\u4e00\u500b\u5177\u540d\u63d2\u69fd `header`\u3001\u4e00\u500b\u9ed8\u8a8d\u63d2\u69fd\u548c\u4e00\u500b\u5177\u540d\u63d2\u69fd `footer`\u3002\u9019\u6a23\u4e00\u4f86\uff0c\u4f60\u53ef\u4ee5\u9748\u6d3b\u5730\u63a7\u5236\u5167\u5bb9\u7684\u986f\u793a\u3002<\/p>\n<h2>\u932f\u8aa4\u6392\u9664\u8207\u6700\u4f73\u5be6\u8e10<\/h2>\n<p>1. **\u672a\u986f\u793a\u63d2\u69fd\u5167\u5bb9**\uff1a\u78ba\u4fdd\u5728\u5143\u4ef6\u4e2d\u6b63\u78ba\u4f7f\u7528 `<slot>` \u6a19\u7c64\uff0c\u4e26\u4e14\u63d2\u69fd\u540d\u7a31\u6b63\u78ba\u7121\u8aa4\u3002<br \/>\n2. **\u6a23\u5f0f\u885d\u7a81**\uff1a\u7576\u4f7f\u7528\u63d2\u69fd\u6642\uff0c\u8acb\u6ce8\u610f\u6a23\u5f0f\u53ef\u80fd\u6703\u5f71\u97ff\u63d2\u5165\u7684\u5167\u5bb9\uff0c\u5efa\u8b70\u4f7f\u7528 scoped CSS \u4f86\u907f\u514d\u6a23\u5f0f\u885d\u7a81\u3002<\/p>\n<h2>\u5ef6\u4f38\u61c9\u7528<\/h2>\n<p>\u63d2\u69fd\u5728 Vue.js \u61c9\u7528\u4e2d\u975e\u5e38\u6709\u7528\uff0c\u5c24\u5176\u662f\u5728\u958b\u767c\u53ef\u91cd\u7528\u7684 UI \u5143\u4ef6\u6642\u3002\u4f60\u53ef\u4ee5\u5c07\u63d2\u69fd\u61c9\u7528\u65bc\u4ee5\u4e0b\u5834\u666f\uff1a<\/p>\n<p>&#8211; \u5efa\u7acb\u6a21\u614b\u8996\u7a97\u6216\u5c0d\u8a71\u6846\u5143\u4ef6\u3002<br \/>\n&#8211; \u5be6\u4f5c\u52d5\u614b\u6a19\u7c64\u6216\u9078\u55ae\u3002<br \/>\n&#8211; \u5275\u5efa\u5177\u6709\u591a\u7a2e\u5167\u5bb9\u986f\u793a\u7684\u5361\u7247\u5143\u4ef6\u3002<\/p>\n<h2>\u7d50\u8ad6<\/h2>\n<p>\u5728\u672c\u6587\u4e2d\uff0c\u6211\u5011\u4ecb\u7d39\u4e86\u5982\u4f55\u5728 Vue.js \u4e2d\u4f7f\u7528\u63d2\u69fd\uff0c\u5305\u62ec\u57fa\u672c\u63d2\u69fd\u548c\u5177\u540d\u63d2\u69fd\u7684\u4f7f\u7528\u65b9\u6cd5\u3002\u6211\u5011\u9084\u63d0\u4f9b\u4e86\u4e00\u4e9b\u932f\u8aa4\u6392\u9664\u7684\u5efa\u8b70\u548c\u6700\u4f73\u5be6\u8e10\uff0c\u5e6b\u52a9\u4f60\u66f4\u597d\u5730\u4f7f\u7528\u9019\u4e00\u5f37\u5927\u529f\u80fd\u3002\u73fe\u5728\uff0c\u4f60\u53ef\u4ee5\u958b\u59cb\u5728\u4f60\u7684 Vue.js \u61c9\u7528\u7a0b\u5f0f\u4e2d\u4f7f\u7528\u63d2\u69fd\uff0c\u63d0\u9ad8\u5176\u53ef\u8b80\u6027\u548c\u53ef\u7dad\u8b77\u6027\uff01<\/p>\n<h2>\u5e38\u898b\u554f\u984c\u89e3\u7b54\uff08Q&#038;A\uff09<\/h2>\n<h3>1. \u63d2\u69fd\u8207\u5177\u540d\u63d2\u69fd\u6709\u4ec0\u9ebc\u5340\u5225\uff1f<\/h3>\n<p>\u63d2\u69fd\u662f\u7528\u65bc\u63d2\u5165\u5167\u5bb9\u7684\u57fa\u672c\u65b9\u5f0f\uff0c\u800c\u5177\u540d\u63d2\u69fd\u5247\u5141\u8a31\u4f60\u70ba\u4e0d\u540c\u7684\u63d2\u69fd\u6307\u5b9a\u540d\u7a31\uff0c\u4ee5\u4fbf\u5728\u4f7f\u7528\u5143\u4ef6\u6642\u66f4\u9748\u6d3b\u5730\u63d2\u5165\u5167\u5bb9\u3002<\/p>\n<h3>2. \u5982\u4f55\u5728 Vue 3 \u4e2d\u4f7f\u7528\u63d2\u69fd\uff1f<\/h3>\n<p>\u5728 Vue 3 \u4e2d\uff0c\u63d2\u69fd\u7684\u4f7f\u7528\u65b9\u6cd5\u8207 Vue 2 \u57fa\u672c\u76f8\u540c\uff0c\u4f46\u4f60\u53ef\u4ee5\u4f7f\u7528 `v-slot` \u6307\u4ee4\u4f86\u7c21\u5316\u5177\u540d\u63d2\u69fd\u7684\u5beb\u6cd5\u3002<\/p>\n<h3>3. \u63d2\u69fd\u53ef\u4ee5\u5d4c\u5957\u4f7f\u7528\u55ce\uff1f<\/h3>\n<p>\u662f\u7684\uff0c\u4f60\u53ef\u4ee5\u5728\u63d2\u69fd\u4e2d\u5d4c\u5957\u5176\u4ed6\u63d2\u69fd\uff0c\u9019\u6a23\u53ef\u4ee5\u5275\u5efa\u66f4\u8907\u96dc\u7684\u5143\u4ef6\u7d50\u69cb\uff0c\u4e26\u63d0\u4f9b\u66f4\u9748\u6d3b\u7684\u5167\u5bb9\u63d2\u5165\u65b9\u5f0f\u3002<br \/>\n&#8212;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981\uff1a\u672c\u6587\u5c07\u4ecb\u7d39Vue.js\u4e2d\u63d2\u69fd\u7684\u6982\u5ff5\uff0c\u4ee5\u53ca\u5982\u4f55\u4f7f\u7528\u63d2\u69fd\u4f86\u69cb\u5efa\u53ef\u91cd\u7528\u7684\u7d44\u4ef6\uff0c\u4ee5\u63d0\u9ad8\u958b\u767c\u6548\u7387\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0e\u63d2\u69fd\u7684\u529f\u80fd\uff0c\u4ee5\u53ca\u5982\u4f55\u5728Vue.js\u4e2d\u6709\u6548\u5730\u4f7f\u7528\u5b83\u5011\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[180,179],"tags":[178,177],"class_list":["post-5871","post","type-post","status-publish","format-standard","hentry","category-vue","category-vue-js","tag-vue","tag-vue-js"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-1wH","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5871","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/comments?post=5871"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5871\/revisions"}],"predecessor-version":[{"id":5872,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/5871\/revisions\/5872"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=5871"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=5871"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=5871"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}