component
-
参数:
{string} name{Function | Object} [definition]
-
返回值:
- 如果传入
definition参数,则返回应用实例。 - 如果不传入
definition参数,则返回组件定义。
- 如果传入
-
用法:
注册或检索全局组件。注册还会使用给定的
name参数自动设置组件的name。 -
示例1:
import { createApp } from 'vue'
const app = createApp({})
// 注册一个选项对象
app.component('my-component', {
/* ... */
})
// 检索注册的组件
const MyComponent = app.component('my-component')
-
示例2:
-
局部组件使用
<template>
<el-tabel v-bind="xxx"/>
</template>
<script lang="ts" setup>
import el-tabel from 'element-ui'
</script>
-
示例3:
-
局部组件使用
<template>
<el-tabel v-bind="xxx"/>
</template>
<script lang="ts">
import el-tabel from 'element-ui'
export default {
component: {
el-tabel: el-tabel
}
}
</script>