1.main.js

  1. import BsBtn from '@/components/BsBtn.vue';
  2. Vue.component('BsBtn',BsBtn)

2.components/BsBtn.vue

  1. <template>
  2. <div>
  3. <slot name="header"></slot>
  4. <button class="btn">默认按钮</button>
  5. </div>
  6. </template>
  7. <script>
  8. export default {
  9. }
  10. </script>
  11. <style scoped>
  12. .btn{
  13. width: 100px;
  14. height: 35px;
  15. background: red;
  16. }
  17. </style>

3.使用

  1. <template>
  2. <div>
  3. mv
  4. <p>{{"从你的全世界路过" | format()}}</p>
  5. <bs-btn>
  6. <p slot="header">hello world</p> //插槽
  7. </bs-btn>
  8. </div>