[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"$KiqIp5Qu8t":3,"vue-tips-\u002Fvue-tips\u002Fexpose-slots-from-a-child-component":52,"blogToc-\u002Fvue-tips\u002Fexpose-slots-from-a-child-component":373,"vue-tips-surrounding-\u002Fvue-tips\u002Fexpose-slots-from-a-child-component":588},{"id":4,"extension":5,"items":6,"meta":49,"stem":50,"__hash__":51},"menu\u002Fmenu.json","json",[7,12,16,20,24,28,32,36,41,45],{"i18nId":8,"to":9,"ariaLabel":10,"mainNavigation":11},"components.menu.home","\u002F","Home",true,{"i18nId":13,"to":14,"ariaLabel":15,"mainNavigation":11},"components.menu.about","\u002Fhire-me","About",{"i18nId":17,"to":18,"ariaLabel":19,"mainNavigation":11},"components.menu.testimonials","\u002Ftestimonials","Testimonials",{"i18nId":21,"to":22,"ariaLabel":23},"components.menu.contact","\u002Fcontact","Contact",{"i18nId":25,"to":26,"ariaLabel":27,"mainNavigation":11},"components.menu.blog","\u002Fblog","Blog",{"i18nId":29,"to":30,"ariaLabel":31,"mainNavigation":11},"components.menu.tips","\u002Fvue-tips","Vue Tips",{"i18nId":33,"to":34,"ariaLabel":35,"mainNavigation":11},"components.menu.projects","\u002Fprojects","Projects",{"i18nId":37,"to":38,"ariaLabel":39,"mainNavigation":40},"components.menu.stats","\u002Fstats","stats",false,{"i18nId":42,"to":43,"ariaLabel":44,"mainNavigation":40},"components.menu.businessCard","\u002Fbusiness-card","Business Card",{"i18nId":46,"to":47,"ariaLabel":48,"mainNavigation":40},"components.menu.publications","\u002Fpublications","Publications",{},"menu","njLT1QoRt2Dv8QWoVmH8xdTAiDywSj0bxBQdmoyWUE0",{"id":53,"title":54,"body":55,"categories":356,"cover":358,"date":359,"description":61,"extension":360,"lastUpdated":361,"meta":362,"navigation":11,"ogImage":361,"path":363,"readingTime":364,"robots":361,"schemaOrg":361,"seo":369,"sitemap":370,"stem":371,"tags":361,"__hash__":372},"vueTips\u002Fvue-tips\u002Fexpose-slots-from-a-child-component\u002Findex.md","Vue Tip: Expose Slots From a Child Component ",{"type":56,"value":57,"toc":354},"minimark",[58,62,65,293,303,306,350],[59,60,61],"p",{},"Third-party components are often wrapped in a custom component. But in that way, the slots of the third-party component get lost.",[59,63,64],{},"The following solution exposes all slots of the third-party component to the parent component:",[66,67,78],"pre",{"className":68,"code":69,"filename":70,"highlights":71,"language":76,"meta":77,"style":77},"language-vue shiki shiki-themes github-light poimandres poimandres","\u003Ctemplate>\n  \u003Cdiv class=\"wrapper\">\n    \u003CThirdPartyComponent v-bind=\"$attrs\">\n      \u003C!-- Expose all slots of the third-party component -->\n      \u003Ctemplate v-for=\"(_, name) in $slots\" #[name]=\"slotProps\">\n        \u003Cslot :name=\"name\" v-bind=\"slotProps || {}\">\u003C\u002Fslot>\n      \u003C\u002Ftemplate>\n    \u003C\u002FThirdPartyComponent>\n  \u003C\u002Fdiv>\n\u003C\u002Ftemplate>\n","WrapperComponent.vue",[72,73,74,75],4,5,6,7,"vue","",[79,80,81,97,126,149,157,215,253,263,273,283],"code",{"__ignoreMap":77},[82,83,86,90,94],"span",{"class":84,"line":85},"line",1,[82,87,89],{"class":88},"sMzB8","\u003C",[82,91,93],{"class":92},"s8PnL","template",[82,95,96],{"class":88},">\n",[82,98,100,103,106,110,114,118,122,124],{"class":84,"line":99},2,[82,101,102],{"class":88},"  \u003C",[82,104,105],{"class":92},"div",[82,107,109],{"class":108},"sppiw"," class",[82,111,113],{"class":112},"sygvE","=",[82,115,117],{"class":116},"srEIG","\"",[82,119,121],{"class":120},"skTdI","wrapper",[82,123,117],{"class":116},[82,125,96],{"class":88},[82,127,129,132,135,138,140,142,145,147],{"class":84,"line":128},3,[82,130,131],{"class":88},"    \u003C",[82,133,134],{"class":92},"ThirdPartyComponent",[82,136,137],{"class":108}," v-bind",[82,139,113],{"class":112},[82,141,117],{"class":116},[82,143,144],{"class":88},"$attrs",[82,146,117],{"class":116},[82,148,96],{"class":88},[82,150,153],{"class":151,"line":72},[84,152],"highlight",[82,154,156],{"class":155},"s1MN7","      \u003C!-- Expose all slots of the third-party component -->\n",[82,158,160,163,165,169,171,173,176,179,182,185,188,192,195,197,200,203,206,208,211,213],{"class":159,"line":73},[84,152],[82,161,162],{"class":88},"      \u003C",[82,164,93],{"class":92},[82,166,168],{"class":167},"sOygg"," v-for",[82,170,113],{"class":112},[82,172,117],{"class":116},[82,174,175],{"class":112},"(",[82,177,178],{"class":88},"_",[82,180,181],{"class":112},",",[82,183,184],{"class":88}," name",[82,186,187],{"class":112},")",[82,189,191],{"class":190},"slWGy"," in",[82,193,194],{"class":88}," $slots",[82,196,117],{"class":116},[82,198,199],{"class":112}," #[",[82,201,202],{"class":88},"name",[82,204,205],{"class":112},"]=",[82,207,117],{"class":116},[82,209,210],{"class":88},"slotProps",[82,212,117],{"class":116},[82,214,96],{"class":88},[82,216,218,221,224,227,229,231,233,235,237,239,241,244,246,249,251],{"class":217,"line":74},[84,152],[82,219,220],{"class":88},"        \u003C",[82,222,223],{"class":92},"slot",[82,225,226],{"class":108}," :name",[82,228,113],{"class":112},[82,230,117],{"class":116},[82,232,202],{"class":120},[82,234,117],{"class":116},[82,236,137],{"class":108},[82,238,113],{"class":112},[82,240,117],{"class":116},[82,242,243],{"class":120},"slotProps || {}",[82,245,117],{"class":116},[82,247,248],{"class":88},">\u003C\u002F",[82,250,223],{"class":92},[82,252,96],{"class":88},[82,254,256,259,261],{"class":255,"line":75},[84,152],[82,257,258],{"class":88},"      \u003C\u002F",[82,260,93],{"class":92},[82,262,96],{"class":88},[82,264,266,269,271],{"class":84,"line":265},8,[82,267,268],{"class":88},"    \u003C\u002F",[82,270,134],{"class":92},[82,272,96],{"class":88},[82,274,276,279,281],{"class":84,"line":275},9,[82,277,278],{"class":88},"  \u003C\u002F",[82,280,105],{"class":92},[82,282,96],{"class":88},[82,284,286,289,291],{"class":84,"line":285},10,[82,287,288],{"class":88},"\u003C\u002F",[82,290,93],{"class":92},[82,292,96],{"class":88},[59,294,295,296,299,300,302],{},"Now every component that uses ",[79,297,298],{},"WrapperComponent"," can use the slots of ",[79,301,134],{},".",[59,304,305],{},"What's happening:",[307,308,309,323,337],"ol",{},[310,311,312,313,315,316,187],"li",{},"We insert the third-party component and bind its attributes via the ",[79,314,144],{}," component instance object (",[317,318,322],"a",{"href":319,"rel":320},"https:\u002F\u002Fvuejs.org\u002Fapi\u002Fcomponent-instance.html#attrs",[321],"nofollow","official docs",[310,324,325,326,315,329,333,334],{},"We loop over all available slots using the ",[79,327,328],{},"$slots",[317,330,322],{"href":331,"rel":332},"https:\u002F\u002Fvuejs.org\u002Fapi\u002Fcomponent-instance.html#slots",[321],") and bind the slots props to the slot name via ",[79,335,336],{},"#[name]=\"slotProps\"",[310,338,339,340,342,343,346,347,349],{},"In the ",[79,341,223],{},", we use ",[79,344,345],{},"v-bind"," to bind all third-party slot properties (",[79,348,210],{},") to pass out to a parent",[351,352,353],"style",{},"html pre.shiki code .sMzB8, html code.shiki .sMzB8{--shiki-light:#24292E;--shiki-default:#E4F0FB;--shiki-dark:#E4F0FB}html pre.shiki code .s8PnL, html code.shiki .s8PnL{--shiki-light:#22863A;--shiki-default:#5DE4C7;--shiki-dark:#5DE4C7}html pre.shiki code .sppiw, html code.shiki .sppiw{--shiki-light:#6F42C1;--shiki-light-font-style:inherit;--shiki-default:#91B4D5;--shiki-default-font-style:italic;--shiki-dark:#91B4D5;--shiki-dark-font-style:italic}html pre.shiki code .sygvE, html code.shiki .sygvE{--shiki-light:#24292E;--shiki-default:#A6ACCD;--shiki-dark:#A6ACCD}html pre.shiki code .srEIG, html code.shiki .srEIG{--shiki-light:#032F62;--shiki-default:#A6ACCD;--shiki-dark:#A6ACCD}html pre.shiki code .skTdI, html code.shiki .skTdI{--shiki-light:#032F62;--shiki-default:#5DE4C7;--shiki-dark:#5DE4C7}html pre.shiki code .s1MN7, html code.shiki .s1MN7{--shiki-light:#6A737D;--shiki-light-font-style:inherit;--shiki-default:#767C9DB0;--shiki-default-font-style:italic;--shiki-dark:#767C9DB0;--shiki-dark-font-style:italic}html pre.shiki code .sOygg, html code.shiki .sOygg{--shiki-light:#D73A49;--shiki-default:#A6ACCD;--shiki-dark:#A6ACCD}html pre.shiki code .slWGy, html code.shiki .slWGy{--shiki-light:#D73A49;--shiki-default:#91B4D5;--shiki-dark:#91B4D5}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":77,"searchDepth":99,"depth":99,"links":355},[],[93,357],"slots","vue-tips\u002Fexpose-slots-from-a-child-component-static-v1.jpg","2022-10-01","md",null,{},"\u002Fvue-tips\u002Fexpose-slots-from-a-child-component",{"text":365,"minutes":366,"time":367,"words":368},"1 min read",0.64,38400,128,{"title":54,"description":61},{"loc":363,"lastmod":359},"vue-tips\u002Fexpose-slots-from-a-child-component\u002Findex","voq9waqxY-p7hYk1jFOyJFHUhGYzjMJeVYKkwa3U9lg",{"id":374,"title":54,"body":375,"cover":358,"description":61,"extension":360,"meta":582,"navigation":11,"path":363,"robots":361,"seo":585,"sitemap":586,"stem":371,"__hash__":587},"content\u002Fvue-tips\u002Fexpose-slots-from-a-child-component\u002Findex.md",{"type":56,"value":376,"toc":580},[377,379,381,544,550,552,578],[59,378,61],{},[59,380,64],{},[66,382,384],{"className":68,"code":69,"filename":70,"highlights":383,"language":76,"meta":77,"style":77},[72,73,74,75],[79,385,386,394,412,430,435,478,511,520,528,536],{"__ignoreMap":77},[82,387,388,390,392],{"class":84,"line":85},[82,389,89],{"class":88},[82,391,93],{"class":92},[82,393,96],{"class":88},[82,395,396,398,400,402,404,406,408,410],{"class":84,"line":99},[82,397,102],{"class":88},[82,399,105],{"class":92},[82,401,109],{"class":108},[82,403,113],{"class":112},[82,405,117],{"class":116},[82,407,121],{"class":120},[82,409,117],{"class":116},[82,411,96],{"class":88},[82,413,414,416,418,420,422,424,426,428],{"class":84,"line":128},[82,415,131],{"class":88},[82,417,134],{"class":92},[82,419,137],{"class":108},[82,421,113],{"class":112},[82,423,117],{"class":116},[82,425,144],{"class":88},[82,427,117],{"class":116},[82,429,96],{"class":88},[82,431,433],{"class":432,"line":72},[84,152],[82,434,156],{"class":155},[82,436,438,440,442,444,446,448,450,452,454,456,458,460,462,464,466,468,470,472,474,476],{"class":437,"line":73},[84,152],[82,439,162],{"class":88},[82,441,93],{"class":92},[82,443,168],{"class":167},[82,445,113],{"class":112},[82,447,117],{"class":116},[82,449,175],{"class":112},[82,451,178],{"class":88},[82,453,181],{"class":112},[82,455,184],{"class":88},[82,457,187],{"class":112},[82,459,191],{"class":190},[82,461,194],{"class":88},[82,463,117],{"class":116},[82,465,199],{"class":112},[82,467,202],{"class":88},[82,469,205],{"class":112},[82,471,117],{"class":116},[82,473,210],{"class":88},[82,475,117],{"class":116},[82,477,96],{"class":88},[82,479,481,483,485,487,489,491,493,495,497,499,501,503,505,507,509],{"class":480,"line":74},[84,152],[82,482,220],{"class":88},[82,484,223],{"class":92},[82,486,226],{"class":108},[82,488,113],{"class":112},[82,490,117],{"class":116},[82,492,202],{"class":120},[82,494,117],{"class":116},[82,496,137],{"class":108},[82,498,113],{"class":112},[82,500,117],{"class":116},[82,502,243],{"class":120},[82,504,117],{"class":116},[82,506,248],{"class":88},[82,508,223],{"class":92},[82,510,96],{"class":88},[82,512,514,516,518],{"class":513,"line":75},[84,152],[82,515,258],{"class":88},[82,517,93],{"class":92},[82,519,96],{"class":88},[82,521,522,524,526],{"class":84,"line":265},[82,523,268],{"class":88},[82,525,134],{"class":92},[82,527,96],{"class":88},[82,529,530,532,534],{"class":84,"line":275},[82,531,278],{"class":88},[82,533,105],{"class":92},[82,535,96],{"class":88},[82,537,538,540,542],{"class":84,"line":285},[82,539,288],{"class":88},[82,541,93],{"class":92},[82,543,96],{"class":88},[59,545,295,546,299,548,302],{},[79,547,298],{},[79,549,134],{},[59,551,305],{},[307,553,554,561,570],{},[310,555,312,556,315,558,187],{},[79,557,144],{},[317,559,322],{"href":319,"rel":560},[321],[310,562,325,563,315,565,333,568],{},[79,564,328],{},[317,566,322],{"href":331,"rel":567},[321],[79,569,336],{},[310,571,339,572,342,574,346,576,349],{},[79,573,223],{},[79,575,345],{},[79,577,210],{},[351,579,353],{},{"title":77,"searchDepth":99,"depth":99,"links":581},[],{"categories":583,"date":359,"readingTime":584},[93,357],{"text":365,"minutes":366,"time":367,"words":368},{"title":54,"description":61},{"loc":363,"lastmod":359},"cJeCyw_J6PuexfxgvvymnZe90hz20JdvpU7gRP3r8oc",[589,593],{"title":590,"path":591,"stem":592,"children":-1},"Vue Tip: Expose Properties in a Script Setup Component","\u002Fvue-tips\u002Fexpose-properties-in-a-script-setup-component","vue-tips\u002Fexpose-properties-in-a-script-setup-component\u002Findex",{"title":594,"path":595,"stem":596,"children":-1},"Vue Tip: Lifecycle Hooks for Debugging","\u002Fvue-tips\u002Flifecycle-hooks-for-debugging","vue-tips\u002Flifecycle-hooks-for-debugging\u002Findex"]