Vue中的全局组件注册

2023-10-10 12:47:16 浏览数 (13)

Vue中的全局组件注册

compontents 属于通用组件,需要在多个组件下使用,建议使用注册全局组件

注册方式(插件化手段)
代码语言:javascript复制
// 把components中的所有组件都进行全局化注册
// 通过插件的方式
import ImageView from './imageView/index.vue'
import Sku from './XtxSku/index.vue'

export const componentPlugin = {
  install (app) {
    // app.component('组件名字',组件配置对象)  component 全局方法
    app.component('ImageView', ImageView)
    app.component('XtxSku', Sku)
  }
}
主要通过 component 全局方法 ,切记使用组件可以不用导入 但对应组件名要一样

0 人点赞