下面为案例:
1、自定义一个按钮组件
<template>
<button class="btn-primary">
<slot></slot>
</button>
</template>
<script>
export default {
}
</script>
<style lang="scss">
.btn-primary {
padding: 5px 10px;
background: orange;
color: #fff;
border: none;
}
</style>
2、调用这个组件
<v-button class="btn-primary">登录</v-button>slot还允许在自定义组件里面传入任意的html标签,或者其他组件
<v-button class="btn-primary">
<i>Icon</i> 登录
</v-button>
slot中还可以绑定父组件的数据
<v-button class="btn-primary">
<i>Icon</i> 登录
{{title}}
</v-button>
