APP父组件引入子组件 通过卡槽添加数据
app.vue
<template>
<div id="app">
<Article>
<template #title>
<h1>标题</h1>
</template>
<template v-slot:content>
<h2>内容</h2>
</template>
<template #auth>
<h3>作者</h3>
</template>
</Article>
</div>
</template>
<script>
import Article from "@/components/Article";
export default {
name: "App",
components: {
Article,
},
};
</script>
<style lang="less">
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>
article.vue
<template>
<div>
<div class="title" msg="vue 您好">
<slot name="title">
</slot>
</div>
<hr />
<div class="content">
<slot name="content">
</slot>
</div>
<hr />
<div class="auth">
<slot name="auth">
</slot>
</div>
</div>
</template>
<script>
export default {
}
</script>
<style scoped>
.title{
padding:10px;
background: green;
color:#fff;
}
.content{
padding:10px;
background: deeppink;
color:#fff;
}
.auth{
padding:10px;
background: blue;
color:#fff;
}
</style>