{"id":1304,"date":"2019-09-16T21:55:48","date_gmt":"2019-09-16T13:55:48","guid":{"rendered":"https:\/\/www.develop-note.com\/blog\/?p=1304"},"modified":"2022-02-17T15:13:36","modified_gmt":"2022-02-17T07:13:36","slug":"2020ironman-svelte-named-slots","status":"publish","type":"post","link":"https:\/\/www.develop-note.com\/blog\/2019\/09\/16\/2020ironman-svelte-named-slots\/","title":{"rendered":"\u7b2c\u5341\u4e00\u5c46\u9435\u4eba\u8cfd \u524d\u7aef\u5de5\u7a0b\u5e2b\u7684\u53e6\u4e00\u500b\u9078\u64c7 svelte DAY15- named slots \u547d\u540d\u63d2\u5ea7"},"content":{"rendered":"<h1>named slots \u5b50\u7bc0\u9ede\u5c31\u662f\u653e\u9019\u88e1<\/h1>\n<p>named slots \u662f\u4ec0\u9ebc\u5462\uff0c\u9084\u8a18\u5f97\u6628\u5929\u8ddf\u5927\u5bb6\u5206\u4eab\u5982\u4f55<a href=\"https:\/\/www.develop-note.com\/blog\/2019\/09\/15\/2020ironman-svelte-slot\/\" title=\"\u4f7f\u7528 slot \u4f86\u88fd\u4f5c\u8907\u5408\u5f0f\u7684\u5143\u4ef6\">\u4f7f\u7528 slot \u4f86\u88fd\u4f5c\u8907\u5408\u5f0f\u7684\u5143\u4ef6<\/a>\uff0c\u4f46\u662f\u5927\u5bb6\u61c9\u8a72\u6703\u554f\u5982\u679c\u6709\u591a\u500b <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/Web_Components\/Using_templates_and_slots\" title=\"slot\" rel=\"nofollow noopener\" target=\"_blank\">slot<\/a>\u3002\u90a3\u8981\u600e\u9ebc\u6c7a\u5b9a\u54ea\u500b\u5167\u5bb9\u8981\u653e\u54ea\u88e1\uff0c\u9019\u500b\u7b54\u6848\u5c31\u662f\u4eca\u5929\u8981\u5206\u4eab\u7684\u5167\u5bb9\u3002<!--more--><\/p>\n<h2>\u9700\u6c42\u662f\u4ec0\u9ebc<\/h2>\n<p>\u5728\u4ecb\u7d39\u547d\u540d\u63d2\u5ea7\u4e4b\u524d\u6211\u60f3\u8acb\u5927\u5bb6\u5148\u770b\u770b\u4e0b\u9762\u7684\u4f8b\u5b50\uff0c\u7c21\u55ae\u63cf\u8ff0\u4e00\u4e0b\u5c31\u662f\u6211\u5011\u6709\u5169\u500b\u5143\u4ef6\uff0c\u5206\u5225\u70baApp.svelte\u8ddfContactCard.svelte\uff0c\u5176\u4e2dApp.svelte\u7684\u529f\u7528\u5728\u65bc\u4f7f\u7528ContactCard\u4e26\u5448\u73fe\u806f\u7d61\u4eba\u7684\u8cc7\u8a0a\uff0c\u5982\u4e0b\u6240\u793a\u3002<\/p>\n<pre><code class=\"language-xml\">&lt;script&gt;\n    import ContactCard from &#039;.\/ContactCard.svelte&#039;;\n&lt;\/script&gt;\n\n&lt;ContactCard&gt;\n    &lt;span slot=&quot;name&quot;&gt;\n        P. Sherman\n    &lt;\/span&gt;\n\n    &lt;span slot=&quot;address&quot;&gt;\n        42 Wallaby Way&lt;br&gt;\n        Sydney\n    &lt;\/span&gt;\n&lt;\/ContactCard&gt;<\/code><\/pre>\n<p>\u800cContactCard.svelte\u7684\u529f\u80fd\u5c31\u5728\u65bc\u5b9a\u7fa9\u806f\u7d61\u7c3f\u7684\u6a23\u5f0f\uff0c\u76f8\u95dc\u5167\u5bb9\u5982\u4e0b\u3002<\/p>\n<pre><code class=\"language-html\">&lt;style&gt;\n    .contact-card {\n        width: 300px;\n        border: 1px solid #aaa;\n        border-radius: 2px;\n        box-shadow: 2px 2px 8px rgba(0,0,0,0.1);\n        padding: 1em;\n    }\n\n    h2 {\n        padding: 0 0 0.2em 0;\n        margin: 0 0 1em 0;\n        border-bottom: 1px solid #ff3e00\n    }\n\n    .address, .email {\n        padding: 0 0 0 1.5em;\n        background:  0 50% no-repeat;\n        background-size: 1em 1em;\n        margin: 0 0 0.5em 0;\n        line-height: 1.2;\n    }\n\n    .address { background-image: url(tutorial\/icons\/map-marker.svg) }\n    .email   { background-image: url(tutorial\/icons\/email.svg) }\n    .missing { color: #999 }\n&lt;\/style&gt;\n\n&lt;article class=&quot;contact-card&quot;&gt;\n    &lt;h2&gt;\n        &lt;slot&gt;\n            &lt;span class=&quot;missing&quot;&gt;Unknown name&lt;\/span&gt;\n        &lt;\/slot&gt;\n    &lt;\/h2&gt;\n\n    &lt;div class=&quot;address&quot;&gt;\n        &lt;slot&gt;\n            &lt;span class=&quot;missing&quot;&gt;Unknown address&lt;\/span&gt;\n        &lt;\/slot&gt;\n    &lt;\/div&gt;\n\n    &lt;div class=&quot;email&quot;&gt;\n        &lt;slot&gt;\n            &lt;span class=&quot;missing&quot;&gt;Unknown email&lt;\/span&gt;\n        &lt;\/slot&gt;\n    &lt;\/div&gt;\n&lt;\/article&gt;<\/code><\/pre>\n<p>\u597d\u4e86\uff0c\u57fa\u672c\u8a2d\u5b9a\u4ecb\u7d39\u5b8c\u4e86\uff0c\u73fe\u5728\u8981\u505a\u7684\u662f\u5c07\u628a\u5c0d\u61c9\u7684\u5167\u5bb9\u586b\u5230\u5c0d\u7684\u4f4d\u7f6e\uff0c\u9019\u8a72\u600e\u9ebc\u8655\u7406\u5462?<\/p>\n<h2>named slots \u547d\u540d\u63d2\u5ea7<\/h2>\n<p>\u6240\u4ee5\u4eca\u5929\u7684\u5167\u5bb9\u5c31\u662f\u8981\u628a\u5c0d\u61c9\u7684\u5167\u5bb9\u586b\u5230\u5c0d\u7684\u4f4d\u7f6e\u4e0a\uff0c\u5728App.svelte\u5167\u6211\u5011\u6709\u8a2d\u5b9a\u5c6c\u6027slot=&quot;name&quot;\u8ddfslot=&quot;address&quot;\u9019\u5c31\u662f\u8981\u6307\u5b9a\u5230\u5c0d\u61c9\u7684slot\u7684\u5c6c\u6027\uff0c\u63a5\u4e0b\u4f86\u6211\u5011\u5c07ContactCard.svelte\u7684html\u5167\u5bb9\u4fee\u6539\u5982\u4e0b\u3002<\/p>\n<pre><code class=\"language-html\">&lt;article class=&quot;contact-card&quot;&gt;\n    &lt;h2&gt;\n        &lt;slot name=&quot;name&quot;&gt;\n            &lt;span class=&quot;missing&quot;&gt;Unknown name&lt;\/span&gt;\n        &lt;\/slot&gt;\n    &lt;\/h2&gt;\n\n    &lt;div class=&quot;address&quot;&gt;\n        &lt;slot name=&quot;address&quot;&gt;\n            &lt;span class=&quot;missing&quot;&gt;Unknown address&lt;\/span&gt;\n        &lt;\/slot&gt;\n    &lt;\/div&gt;\n\n    &lt;div class=&quot;email&quot;&gt;\n        &lt;slot name=&quot;email&quot;&gt;\n            &lt;span class=&quot;missing&quot;&gt;Unknown email&lt;\/span&gt;\n        &lt;\/slot&gt;\n    &lt;\/div&gt;\n&lt;\/article&gt;<\/code><\/pre>\n<p>\u9019\u6a23\u4e00\u4f86\u5c31\u53ef\u4ee5\u5c07\u547d\u540d\u70ba<code>slot=&quot;name&quot;<\/code>\u5c0d\u61c9\u5230<code>slot name=&quot;name&quot;<\/code>\uff0c\u547d\u540d\u70ba<code>slot=&quot;address&quot;<\/code>\u7684\u5c0d\u61c9\u5230<code>slot name=&quot;address&quot;<\/code>\u4e86\uff0c\u7136\u5f8c\u6628\u5929\u63d0\u5230\u7684\u9810\u8a2d\u5167\u5bb9\uff0c\u56e0\u70ba<code>email<\/code>\u6c92\u6709\u5c0d\u61c9\u5230\u6240\u4ee5\u5c31\u986f\u793a\u9810\u8a2d\u5167\u5bb9\u4e86\u3002<\/p>\n<h2>\u5c0f\u7d50<\/h2>\n<p>\u4eca\u5929\u66f4\u9032\u4e00\u6b65\u4ecb\u7d39\u547d\u540d\u63d2\u5ea7\uff0c\u53ef\u4ee5\u5c07\u5b50\u7bc0\u9ede\u8981\u6307\u5b9a\u5230\u5143\u4ef6\u7684\u7279\u5b9a\u4f4d\u7f6e\u7d66\u4e88\u4e00\u500b\u540d\u5b50\uff0c\u9019\u6a23\u5c31\u53ef\u4ee5\u6c7a\u5b9a\u751a\u9ebc\u5b50\u7bc0\u9ede\u8981\u653e\u5728\u751a\u9ebc\u4f4d\u7f6e\u4e86\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>named slots \u5b50\u7bc0\u9ede\u5c31\u662f\u653e\u9019\u88e1 named slots \u662f\u4ec0\u9ebc\u5462\uff0c\u9084\u8a18\u5f97\u6628\u5929\u8ddf\u5927\u5bb6\u5206\u4eab\u5982\u4f55\u4f7f\u7528 sl &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.develop-note.com\/blog\/2019\/09\/16\/2020ironman-svelte-named-slots\/\" class=\"more-link\">\u95b1\u8b80\u5168\u6587<span class=\"screen-reader-text\">\u3008\u7b2c\u5341\u4e00\u5c46\u9435\u4eba\u8cfd \u524d\u7aef\u5de5\u7a0b\u5e2b\u7684\u53e6\u4e00\u500b\u9078\u64c7 svelte DAY15- named slots \u547d\u540d\u63d2\u5ea7\u3009<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[2],"tags":[160,79],"class_list":["post-1304","post","type-post","status-publish","format-standard","hentry","category-develop","tag-2019ironman","tag-svelte"],"_links":{"self":[{"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/posts\/1304","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/comments?post=1304"}],"version-history":[{"count":20,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/posts\/1304\/revisions"}],"predecessor-version":[{"id":3009,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/posts\/1304\/revisions\/3009"}],"wp:attachment":[{"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/media?parent=1304"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/categories?post=1304"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.develop-note.com\/blog\/wp-json\/wp\/v2\/tags?post=1304"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}