子组件
<template>
<div class="card-box">
<div class="card-head">
<slot name="card-head"></slot>
</div>
<div class="card-body">
<slot></slot>
</div>
</div>
</template>
<script>
</script>
<style scoped="scoped">
.card-box{
border: 1px solid cornflowerblue;
border-radius: 2px;
width: 400px;
min-height: 200px;
}
.card-head{
height: 50px;
line-height: 50px;
text-align: left;
padding: 0 5px;
color: white;
font-size: 18px;
background-color: cornflowerblue;
}
.card-body{
text-align: left;
padding: 0 5px;
}
</style>
父组件
<template>
<div id="app">
<Card>
<template slot="card-head">头部</template>
我是内容
</Card>
</div>
</template>
<script>
import Card from './components/Card.vue'
export default {
name: 'app',
components: {
Card
},
data(){
return{
}
},
methods:{
}
}
</script>
<style>
#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>
效果
![](https://img.haomeiwen.com/i15331999/971e28bd4ef3bb72.png)
image.png
网友评论