自定义组件进行全局注册

在学习Vue中,由于想把自定义组件进行全局使用,但组件过多导致main.js中内容过长,理解其原理,类似按需导入的方式注册全局组件。
👉阿勇的博客👈

  1. components目录下新建index.js

  2. 导入已经写好的自定义组件

    1. import OneDialog from './Dialog/index.vue'
      
  3. 对自定义组件进行全局注册

    1. const customize = {
        install(Vue) {
          Vue.component('OneDialog', OneDialog)
        }
      }
      export default customize
      
  4. main.js中进行导入

    1. import customize from './components/index'
      Vue.use(customize)
      
  5. .vue文件中进行使用

posted @ 2021-09-13 14:50  ayong6  阅读(150)  评论(0)    收藏  举报