标签:02 vue 插槽 content header MyArticle main before
app.vue
<template> <div> <h1>App 根组件</h1> <hr /> <!-- 使用组件 --> <my-article> <template #header> <h1>滕王阁序</h1> </template> <template #default> <p>豫章故郡,洪都新府。</p> <p>星分翼轸,地接衡庐</p> <p>襟三江而带五湖,控蛮荆而引瓯越。</p> </template> <template #footer> <p>落款:王勃</p> </template> </my-article> </div> </template> <script> // 导入组件 import MyArticle from './MyArticle.vue' export default { name: 'MyApp', components: { // 注册组件 MyArticle, }, } </script> <style lang="less" scoped></style>MyArticle.vue
<template> <div> <!-- 我们希望把页头放到这里 --> <header> <slot name="header"></slot> </header> <!-- 我们希望把主要内容放到这里 --> <main> <slot></slot> </main> <!-- 我们希望把页脚放到这里 --> <footer> <slot name="footer"></slot> </footer> </div> </template> <script> export default { name: 'MyArticle', } </script> <style lang="less" scoped> header, main, footer { border: 1px dashed #999; margin: 30px; padding: 40px; position: relative; &::before { position: absolute; right: 5px; top: 5px; font-style: italic; } } header::before { content: 'header 页头'; } main::before { content: 'main 主体内容'; } footer::before { content: 'footer 页脚'; } </style>
标签:02,vue,插槽,content,header,MyArticle,main,before 来源: https://www.cnblogs.com/dxboot/p/16347766.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。