zoukankan      html  css  js  c++  java
  • vue-公共组件的注册

    注册公共组件,在每个需要的页面直接输入文件名(<g-table/>)即可引用该组件

    步骤:

    1.新建components/global文件夹,以及components/global/g-table.vue文件。

    2.新建untils/globalComponents-register.js,内容:

    import Vue from 'vue';
    // import 所有组件
    const requireComponent = require.context('@/components/global', true, /.vue$/);
    // 遍历所有组件地址地址
    requireComponent.keys().forEach(fileName => {
        // 文件名作为组件名
        let name = fileName.split('/')[1].split('.')[0];
        const componetConfig = requireComponent(fileName);
        // 注册全局组件
        Vue.component(name, componetConfig.default || componetConfig)
    })

    3.在main.js中引入这个js(引入的js文件比较多时可以在main.js只引入untils/index.js,在index.js中引入其他各js文件)

    4.页面使用:<g-table/> 无需引入

  • 相关阅读:
    Android AdapterView View的复用机制 分析
    go12---interface
    go11---方法method
    go10---struct
    go09---defer
    go8---函数function
    go7---map
    go6---slice切片
    go5--数组
    go4--break,continue + 标签
  • 原文地址:https://www.cnblogs.com/wd163/p/14084480.html
Copyright © 2011-2022 走看看