當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Vue.js app.component()用法及代碼示例

如果同時傳遞名稱字符串和組件定義,則注冊一個全局組件,如果隻傳遞名稱,則檢索已注冊的組件。

類型

interface App {
  component(name: string): Component | undefined
  component(name: string, component: Component): this
}

示例

import { createApp } from 'vue'

const app = createApp({})

// register an options object
app.component('my-component', {
  /* ... */
})

// retrieve a registered component
const MyComponent = app.component('my-component')

相關用法


注:本文由純淨天空篩選整理自vuejs.org大神的英文原創作品 app.component()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。