学习Vue3 第十章(组件1)

52 阅读1分钟

全局组件

import { createApp } from 'vue'
import App from './App.vue'
import Btn from './components/Btn.vue'

const app = createApp(App)

// 注册全局组件
app.component('b-tn', Btn)

app.mount('#app')

局部组件

Card.vue

<template>
  <div>我是一个卡片</div>
</template>
<script setup></script>
<style scoped lang="scss"></style>

App.vue

<template>
  <div>
    <Card />
    <Card />
    <Card />
    <Card />
    <Card />
  </div>
</template>

<script setup>
import Card from './components/Card.vue'
</script>

<style scoped></style>