1.在src/components下面新建xxx文件夹,在xxx文件下新建index.vue文件,此处为多个组件
2.在components文件下新建index.js文件,内容如下
引入需要注册的全局组件
import Icon from './Icon'
import FileUpload from './file-upload/upload'
import Table from './table'
import PermissionArea from './permission-area'
import SysSelect from '../app/sys-select'
import SysCodeName from '../app/sys-select/sys-code-name'
import ArchivesAnnex from '../app/archives-annex'
import AddPerson from '../app/add-person-jiazhaoye'
import ChartWarning from './chart-warning'
import selectableTag from './t-ui/selectable-tag/main'
const components = [
// common
SysSelect,
SysCodeName,
Icon,
Table,
PermissionArea,
FileUpload,
selectableTag,
ArchivesAnnex,
AddPerson,
ChartWarning
]
// 定位insyall函数,函数内部循环注册组件
// Vue参数在使用Vue.use方法时自动传入
// eslint-disable-next-line no-unused-vars
const install = function (Vue, opts = {}) {
components.forEach((component) => {
Vue.component(component.name, component)
})
}
默认导出install函数
export default {
install
}
3.在index.js下使用该插件
import Vue from 'vue'
import CustomComponents from '@/components/common'
Vue.use(CustomComponents, {})