{"id":8510,"date":"2023-11-28T20:30:05","date_gmt":"2023-11-28T12:30:05","guid":{"rendered":"https:\/\/wx.kaifamiao.info\/?p=8510"},"modified":"2023-12-02T22:58:06","modified_gmt":"2023-12-02T14:58:06","slug":"vue-zhong-vue-slot","status":"publish","type":"post","link":"http:\/\/wx.kaifamiao.info\/index.php\/2023\/11\/28\/vue-zhong-vue-slot\/","title":{"rendered":"Vue \u4e2d vue slot\uff1f"},"content":{"rendered":"<p>Vue \u7684\u63d2\u69fd\uff08Slot\uff09\u662f\u4e00\u79cd\u673a\u5236\uff0c\u5141\u8bb8\u4f60\u5728\u7236\u7ec4\u4ef6\u4e2d\u5411\u5b50\u7ec4\u4ef6\u4f20\u9012\u5185\u5bb9\uff0c\u4f7f\u5f97\u5b50\u7ec4\u4ef6\u7684\u90e8\u5206\u5185\u5bb9\u80fd\u591f\u7531\u7236\u7ec4\u4ef6\u51b3\u5b9a\u3002<\/p>\n<h3><a id=\"%E9%BB%98%E8%AE%A4%E6%8F%92%E6%A7%BD%EF%BC%88default-slot%EF%BC%89\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>\u9ed8\u8ba4\u63d2\u69fd\uff08Default Slot\uff09<\/h3>\n<p>\u9ed8\u8ba4\u63d2\u69fd\u662f\u6700\u7b80\u5355\u7684\u63d2\u69fd\u5f62\u5f0f\uff0c\u7528\u4e8e\u5c06\u7236\u7ec4\u4ef6\u7684\u5185\u5bb9\u4f20\u9012\u7ed9\u5b50\u7ec4\u4ef6\u7684\u7279\u5b9a\u4f4d\u7f6e\u3002<\/p>\n<p><strong>\u5b50\u7ec4\u4ef6\uff08ChildComponent.vue\uff09\uff1a<\/strong><\/p>\n<pre><code class=\"language-vue\">&lt;template&gt;\n  &lt;div&gt;\n    &lt;slot&gt;&lt;\/slot&gt;\n    &lt;!-- \u8fd9\u91cc\u7684\u5185\u5bb9\u4f1a\u88ab\u66ff\u6362\u4e3a\u7236\u7ec4\u4ef6\u4f20\u5165\u7684\u5185\u5bb9 --&gt;\n  &lt;\/div&gt;\n&lt;\/template&gt;\n<\/code><\/pre>\n<p><strong>\u7236\u7ec4\u4ef6\u4e2d\u4f7f\u7528\u5b50\u7ec4\u4ef6\uff1a<\/strong><\/p>\n<pre><code class=\"language-vue\">&lt;template&gt;\n  &lt;div&gt;\n    &lt;ChildComponent&gt;\n      &lt;!-- \u8fd9\u91cc\u7684\u5185\u5bb9\u4f1a\u66ff\u6362\u5b50\u7ec4\u4ef6\u4e2d\u7684\u9ed8\u8ba4\u63d2\u69fd --&gt;\n      &lt;p&gt;This is some content passed from the parent.&lt;\/p&gt;\n    &lt;\/ChildComponent&gt;\n  &lt;\/div&gt;\n&lt;\/template&gt;\n\n&lt;script&gt;\nimport ChildComponent from '.\/ChildComponent.vue';\n\nexport default {\n  components: {\n    ChildComponent,\n  },\n};\n&lt;\/script&gt;\n<\/code><\/pre>\n<h3><a id=\"%E5%85%B7%E5%90%8D%E6%8F%92%E6%A7%BD%EF%BC%88named-slot%EF%BC%89\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>\u5177\u540d\u63d2\u69fd\uff08Named Slot\uff09<\/h3>\n<p>\u5177\u540d\u63d2\u69fd\u5141\u8bb8\u4f60\u5728\u5b50\u7ec4\u4ef6\u4e2d\u5b9a\u4e49\u591a\u4e2a\u63d2\u69fd\uff0c\u5e76\u5728\u7236\u7ec4\u4ef6\u4e2d\u6839\u636e\u540d\u5b57\u5206\u53d1\u5185\u5bb9\u3002<\/p>\n<p><strong>\u5b50\u7ec4\u4ef6\uff08ChildComponent.vue\uff09\uff1a<\/strong><\/p>\n<pre><code class=\"language-vue\">&lt;template&gt;\n  &lt;div&gt;\n    &lt;header&gt;\n      &lt;slot name=&quot;header&quot;&gt;&lt;\/slot&gt;\n      &lt;!-- \u8fd9\u91cc\u4f1a\u63a5\u6536\u540d\u4e3a &quot;header&quot; \u7684\u63d2\u69fd\u5185\u5bb9 --&gt;\n    &lt;\/header&gt;\n    &lt;main&gt;\n      &lt;slot&gt;&lt;\/slot&gt;\n      &lt;!-- \u8fd9\u91cc\u4f1a\u63a5\u6536\u9ed8\u8ba4\u63d2\u69fd\u6216\u8005\u6ca1\u6709\u5177\u540d\u63d2\u69fd\u7684\u5185\u5bb9 --&gt;\n    &lt;\/main&gt;\n    &lt;footer&gt;\n      &lt;slot name=&quot;footer&quot;&gt;&lt;\/slot&gt;\n      &lt;!-- \u8fd9\u91cc\u4f1a\u63a5\u6536\u540d\u4e3a &quot;footer&quot; \u7684\u63d2\u69fd\u5185\u5bb9 --&gt;\n    &lt;\/footer&gt;\n  &lt;\/div&gt;\n&lt;\/template&gt;\n<\/code><\/pre>\n<p><strong>\u7236\u7ec4\u4ef6\u4e2d\u4f7f\u7528\u5b50\u7ec4\u4ef6\uff1a<\/strong><\/p>\n<pre><code class=\"language-vue\">&lt;template&gt;\n  &lt;div&gt;\n    &lt;ChildComponent&gt;\n      &lt;!-- \u5206\u53d1\u5230\u9ed8\u8ba4\u63d2\u69fd --&gt;\n      &lt;p&gt;This is some default content passed from the parent.&lt;\/p&gt;\n\n      &lt;!-- \u5206\u53d1\u5230\u540d\u4e3a &quot;header&quot; \u7684\u63d2\u69fd --&gt;\n      &lt;template v-slot:header&gt;\n        &lt;h1&gt;Header content from the parent.&lt;\/h1&gt;\n      &lt;\/template&gt;\n\n      &lt;!-- \u5206\u53d1\u5230\u540d\u4e3a &quot;footer&quot; \u7684\u63d2\u69fd --&gt;\n      &lt;template v-slot:footer&gt;\n        &lt;footer&gt;Footer content from the parent.&lt;\/footer&gt;\n      &lt;\/template&gt;\n    &lt;\/ChildComponent&gt;\n  &lt;\/div&gt;\n&lt;\/template&gt;\n\n&lt;script&gt;\nimport ChildComponent from '.\/ChildComponent.vue';\n\nexport default {\n  components: {\n    ChildComponent,\n  },\n};\n&lt;\/script&gt;\n<\/code><\/pre>\n<p>\u901a\u8fc7\u63d2\u69fd\u673a\u5236\uff0cVue \u63d0\u4f9b\u4e86\u4e00\u79cd\u7075\u6d3b\u7684\u65b9\u5f0f\uff0c\u8ba9\u7236\u7ec4\u4ef6\u80fd\u591f\u5411\u5b50\u7ec4\u4ef6\u4f20\u9012\u5185\u5bb9\uff0c\u5e76\u4e14\u5141\u8bb8\u5b50\u7ec4\u4ef6\u7075\u6d3b\u5730\u5c55\u793a\u8fd9\u4e9b\u5185\u5bb9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Vue \u7684\u63d2\u69fd\uff08Slot\uff09\u662f\u4e00\u79cd\u673a\u5236\uff0c\u5141\u8bb8\u4f60\u5728\u7236\u7ec4\u4ef6\u4e2d\u5411\u5b50\u7ec4\u4ef6\u4f20\u9012\u5185\u5bb9\uff0c\u4f7f\u5f97\u5b50\u7ec4\u4ef6\u7684\u90e8\u5206\u5185\u5bb9\u80fd\u591f\u7531\u7236\u7ec4\u4ef6\u51b3\u5b9a\u3002 [&hellip;]<\/p>\n","protected":false},"author":11,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[114],"tags":[],"class_list":["post-8510","post","type-post","status-publish","format-standard","hentry","category-vue"],"_links":{"self":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/8510","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/comments?post=8510"}],"version-history":[{"count":2,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/8510\/revisions"}],"predecessor-version":[{"id":14124,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/8510\/revisions\/14124"}],"wp:attachment":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/media?parent=8510"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/categories?post=8510"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/tags?post=8510"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}