{"id":6001,"date":"2025-06-11T09:31:47","date_gmt":"2025-06-17T02:25:46","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=6001"},"modified":"2025-06-17T09:31:47","modified_gmt":"2025-06-17T02:25:46","slug":"%e5%ad%b8%e7%bf%92%e5%a6%82%e4%bd%95%e5%9c%a8vue%e4%b8%ad%e4%bd%bf%e7%94%a8%e6%8f%92%e6%a7%bdslots%e9%80%b2%e8%a1%8c%e7%b5%84%e4%bb%b6%e5%85%a7%e5%ae%b9%e5%88%86%e7%99%bc","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%e4%b8%ad%e4%bd%bf%e7%94%a8%e6%8f%92%e6%a7%bdslots%e9%80%b2%e8%a1%8c%e7%b5%84%e4%bb%b6%e5%85%a7%e5%ae%b9%e5%88%86%e7%99%bc\/","title":{"rendered":"\u6df1\u5165\u4e86\u89e3 Vue 3 \u7684\u63d2\u69fd\uff08Slots\uff09\u529f\u80fd\u8207\u6700\u4f73\u5be6\u8e10"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"Vue, Slots, \u7ec4\u4ef6\u5185\u5bb9\u5206\u53d1, Vue 3 \u63d2\u69fd, Vue \u6559\u5b78, JavaScript \u6846\u67b6\"><\/p>\n<h2>\u4ec0\u9ebc\u662f\u63d2\u69fd\uff08Slots\uff09<\/h2>\n<p>Vue.js \u662f\u4e00\u500b\u8f15\u91cf\u7d1a\u7684 JavaScript \u6846\u67b6\uff0c\u5c08\u70ba\u5feb\u901f\u958b\u767c\u9ad8\u54c1\u8cea\u7684 Web \u61c9\u7528\u7a0b\u5f0f\u800c\u8a2d\u8a08\u3002\u63d2\u69fd\uff08slots\uff09\u662f Vue \u4e2d\u4e00\u500b\u5f37\u5927\u7684\u529f\u80fd\uff0c\u5141\u8a31\u958b\u767c\u8005\u5728\u7d44\u4ef6\u4e2d\u81ea\u7531\u5730\u63d2\u5165\u5167\u5bb9\uff0c\u5f9e\u800c\u5be6\u73fe\u9748\u6d3b\u7684\u7d44\u4ef6\u5167\u5bb9\u5206\u767c\u3002<\/p>\n<h2>\u70ba\u4ec0\u9ebc\u8981\u4f7f\u7528\u63d2\u69fd<\/h2>\n<p>\u4f7f\u7528\u63d2\u69fd\u7684\u4e3b\u8981\u597d\u8655\u662f\u80fd\u5920\u63d0\u9ad8\u7d44\u4ef6\u7684\u91cd\u7528\u6027\u548c\u9748\u6d3b\u6027\u3002\u958b\u767c\u8005\u53ef\u4ee5\u5c07\u7d44\u4ef6\u7684\u5167\u5bb9\u5206\u767c\u5230\u4e0d\u540c\u7684\u5340\u57df\uff0c\u800c\u4e0d\u5fc5\u4e8b\u5148\u5c07\u5167\u5bb9\u5beb\u6b7b\u5728\u7d44\u4ef6\u4e2d\uff0c\u9019\u6a23\u5c31\u80fd\u5920\u8b93\u7d44\u4ef6\u66f4\u5177\u901a\u7528\u6027\u3002<\/p>\n<h2>\u63d2\u69fd\u7684\u985e\u578b<\/h2>\n<p>Vue.js \u63d0\u4f9b\u4e86\u5169\u7a2e\u4e3b\u8981\u7684\u63d2\u69fd\u985e\u578b\uff1a<\/p>\n<ul>\n<li><strong>\u5177\u540d\u63d2\u69fd\uff08Named Slots\uff09<\/strong>: \u5141\u8a31\u4f60\u5c07\u5167\u5bb9\u63d2\u5165\u5230\u7279\u5b9a\u7684\u63d2\u69fd\u4f4d\u7f6e\u3002<\/li>\n<li><strong>\u533f\u540d\u63d2\u69fd\uff08Default Slots\uff09<\/strong>: \u7528\u65bc\u63d2\u5165\u672a\u547d\u540d\u7684\u5167\u5bb9\uff0c\u901a\u5e38\u7528\u65bc\u4e3b\u8981\u5167\u5bb9\u5340\u57df\u3002<\/li>\n<\/ul>\n<h2>\u5982\u4f55\u4f7f\u7528\u63d2\u69fd<\/h2>\n<p>\u4ee5\u4e0b\u662f\u4e00\u500b\u4f7f\u7528 Vue 3 \u63d2\u69fd\u7684\u7c21\u55ae\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u5728\u7d44\u4ef6\u4e2d\u5b9a\u7fa9\u548c\u4f7f\u7528\u63d2\u69fd\uff1a<\/p>\n<h3>\u6b65\u9a5f 1: \u5b9a\u7fa9\u63d2\u69fd\u7684\u7d44\u4ef6<\/h3>\n<pre><code class=\"language-html\">\n<template>\n  <div>\n    <!-- \u5177\u540d\u63d2\u69fd -->\n    <slot name=\"header\"><\/slot>\n\n    <!-- \u533f\u540d\u63d2\u69fd -->\n    <slot><\/slot>\n\n    <!-- \u5177\u540d\u63d2\u69fd -->\n    <slot name=\"footer\"><\/slot>\n  <\/div>\n<\/template>\n<\/code><\/pre>\n<h3>\u6b65\u9a5f 2: \u5728\u7236\u7d44\u4ef6\u4e2d\u4f7f\u7528\u63d2\u69fd<\/h3>\n<pre><code class=\"language-html\">\n<template>\n  <child-component>\n    <template v-slot:header>\n      <h1>This is the header<\/h1>\n    <\/template>\n\n    This is the main content\n\n    <template v-slot:footer>\n      <h2>This is the footer<\/h2>\n    <\/template>\n  <\/child-component>\n<\/template>\n<\/code><\/pre>\n<h2>\u932f\u8aa4\u6392\u9664<\/h2>\n<p>\u5728\u4f7f\u7528\u63d2\u69fd\u6642\uff0c\u53ef\u80fd\u6703\u9047\u5230\u4e00\u4e9b\u5e38\u898b\u7684\u932f\u8aa4\uff1a<\/p>\n<ul>\n<li><strong>\u63d2\u69fd\u672a\u986f\u793a\u5167\u5bb9<\/strong>: \u78ba\u4fdd\u7236\u7d44\u4ef6\u6b63\u78ba\u4f7f\u7528\u4e86\u63d2\u69fd\u540d\u7a31\uff0c\u4e26\u6aa2\u67e5\u662f\u5426\u6709\u62fc\u5beb\u932f\u8aa4\u3002<\/li>\n<li><strong>\u5177\u540d\u63d2\u69fd\u672a\u6b63\u78ba\u6e32\u67d3<\/strong>: \u78ba\u4fdd\u5728\u5b50\u7d44\u4ef6\u4e2d\u5b9a\u7fa9\u4e86\u5c0d\u61c9\u7684\u5177\u540d\u63d2\u69fd\u3002<\/li>\n<\/ul>\n<h2>\u5ef6\u4f38\u61c9\u7528<\/h2>\n<p>\u63d2\u69fd\u4e0d\u50c5\u53ef\u4ee5\u7528\u65bc\u5167\u5bb9\u5206\u767c\uff0c\u9084\u53ef\u4ee5\u8207\u5176\u4ed6 Vue \u529f\u80fd\u7d50\u5408\u4f7f\u7528\uff0c\u4f8b\u5982\uff1a<strong>\u52d5\u614b\u7d44\u4ef6<\/strong>\u3001<strong>\u904e\u6e21\u6548\u679c<\/strong>\u7b49\uff0c\u4f86\u5275\u5efa\u66f4\u8907\u96dc\u548c\u4e92\u52d5\u6027\u66f4\u5f37\u7684\u7528\u6236\u754c\u9762\u3002<\/p>\n<h2>\u7e3d\u7d50<\/h2>\n<p>\u7e3d\u7684\u4f86\u8aaa\uff0c\u63d2\u69fd\uff08slots\uff09\u662f Vue.js \u63d0\u4f9b\u7684\u4e00\u500b\u5f37\u5927\u529f\u80fd\uff0c\u80fd\u5920\u5e6b\u52a9\u958b\u767c\u8005\u9748\u6d3b\u5730\u8655\u7406\u7d44\u4ef6\u5167\u5bb9\u5206\u767c\uff0c\u63d0\u5347\u7d44\u4ef6\u7684\u53ef\u91cd\u7528\u6027\u548c\u9748\u6d3b\u6027\u3002\u96a8\u8457 Vue 3 \u7684\u63a8\u51fa\uff0c\u63d2\u69fd\u7528\u6cd5\u8b8a\u5f97\u66f4\u52a0\u76f4\u89c0\u4e14\u529f\u80fd\u8c50\u5bcc\u3002<\/p>\n<h2>Q&#038;A\uff08\u5e38\u898b\u554f\u984c\u89e3\u7b54\uff09<\/h2>\n<h3>1. \u63d2\u69fd\u548c\u63d2\u69fd\u7bc4\u672c\u6709\u4ec0\u9ebc\u4e0d\u540c\uff1f<\/h3>\n<p>\u63d2\u69fd\u662f\u7528\u65bc\u986f\u793a\u7236\u7d44\u4ef6\u5167\u5bb9\u7684\u4f48\u5c40\uff0c\u800c\u63d2\u69fd\u7bc4\u672c\u5247\u662f\u7528\u65bc\u5b9a\u7fa9\u63d2\u69fd\u7684\u5916\u89c0\u548c\u884c\u70ba\u3002\u4f7f\u7528\u63d2\u69fd\u7bc4\u672c\u53ef\u4ee5\u66f4\u9748\u6d3b\u5730\u63a7\u5236\u63d2\u69fd\u7684\u5167\u5bb9\u3002<\/p>\n<h3>2. \u5982\u4f55\u5728\u63d2\u69fd\u4e2d\u4f7f\u7528\u689d\u4ef6\u6e32\u67d3\uff1f<\/h3>\n<p>\u53ef\u4ee5\u5728\u63d2\u69fd\u5167\u90e8\u4f7f\u7528 Vue \u7684\u689d\u4ef6\u6e32\u67d3\u8a9e\u6cd5\uff0c\u4f8b\u5982 <code>v-if<\/code> \u6216 <code>v-show<\/code>\uff0c\u4ee5\u6839\u64da\u689d\u4ef6\u52d5\u614b\u986f\u793a\u6216\u96b1\u85cf\u5167\u5bb9\u3002<\/p>\n<h3>3. \u53ef\u4ee5\u5728\u5177\u540d\u63d2\u69fd\u4e2d\u4f7f\u7528\u5176\u4ed6\u7d44\u4ef6\u55ce\uff1f<\/h3>\n<p>\u662f\u7684\uff0c\u4f60\u53ef\u4ee5\u5728\u5177\u540d\u63d2\u69fd\u4e2d\u63d2\u5165\u5176\u4ed6 Vue \u7d44\u4ef6\uff0c\u9019\u6a23\u53ef\u4ee5\u5be6\u73fe\u66f4\u8907\u96dc\u7684\u7d44\u4ef6\u7d50\u69cb\u548c\u5c64\u6b21\u3002<\/p>\n<p>&#8212;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981\uff1aVue.js\u63d0\u4f9b\u4e86\u4e00\u7a2e\u53ef\u4ee5\u5c07\u7d44\u4ef6\u5167\u5bb9\u5206\u767c\u7684\u65b9\u6cd5\uff0c\u7a31\u70ba\u63d2\u69fd(slots)\uff0c\u53ef\u4ee5\u8b93\u958b\u767c\u8005\u5c07\u7d44\u4ef6\u5167\u5bb9\u5206\u767c\u5230\u4e0d\u540c\u7684\u4f4d\u7f6e\uff0c\u66f4\u52a0\u6709\u6548\u5730\u4f7f\u7528\u7d44\u4ef6\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u5728Vue\u4e2d\u4f7f\u7528\u63d2\u69fd(slots)\u9032\u884c\u7d44\u4ef6\u5167\u5bb9\u5206\u767c\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-6001","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-1yN","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/6001","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=6001"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/6001\/revisions"}],"predecessor-version":[{"id":6002,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/6001\/revisions\/6002"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=6001"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=6001"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=6001"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}