# ibi-vue2-comp-use
**Repository Path**: cboard_beta/ibi-vue2-comp-use
## Basic Information
- **Project Name**: ibi-vue2-comp-use
- **Description**: IBI Vue2 组件化样例
- **Primary Language**: Unknown
- **License**: Not specified
- **Default Branch**: main
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2023-01-11
- **Last Updated**: 2023-04-13
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
---
title: Vue2组件化集成
icon:
category: guide
tags:
- 开发者
---
## 安装依赖
- 项目与关键模块版本
```json
{
"vue": "^2.6.14",
"vue-i18n": "^8.28.2",
"vuex": "^3.0.1",
"element-ui": "^2.15.12"
}
```
- 安装第三方npm依赖
```bash
npm install element-ui axios numbro tippy.js file-saver countup.js moment
```
> 项目中原本已经存在的依赖可以不用重复安装
:::details ElementUI按需引入
- 如果您项目中没有用到明细表格,可以不引入element-ui
- 如果您项目中使用的是其他的ui库,又需要使用明细表格,可以按需导入明细表依赖的组件
借助 babel-plugin-component,我们可以只引入需要的组件,以达到减小项目体积的目的。
首先,安装 babel-plugin-component:
```bash
npm install babel-plugin-component -D
```
然后,将 .babelrc 修改为:
```json
{
"presets": [
[
"es2015",
{
"modules": false
}
]
],
"plugins": [
[
"component",
{
"libraryName": "element-ui",
"styleLibraryName": "theme-chalk"
}
]
]
}
```
```javascript
import {
Table,
TableColumn,
Loading,
Row,
Pagination,
Popover,
Input,
Select,
Option,
CheckboxGroup,
Checkbox
} from 'element-ui';
[Table, TableColumn, Loading, Row, Pagination, Popover, Input, Select, Option, CheckboxGroup, Checkbox].forEach(e => Vue.use(e));
```
:::
:::details IBI使用的element-ui定制化说明
IBI对element-ui做了一些个性化定制工作,如:明细表分页按钮样式配置、颜色拾取器风格、各种表单样式属性等,但基本不影响原生功能,
如果您需要整合之后呈现的效果与IBI一致可以把
```javascript
import ElementUI from 'element-ui';
Vue.use(ElementUI);
```
修改为
```javascript
import ChuguoUI from 'chuguo-ui';
Vue.use(ChuguoUI);
````
:::
- 安装IBI npm依赖
```
npm install @chuguotech/ibi-vue2-comp
```
- 其他外挂依赖
```
$ tree -L 1 vendor
vendor
├── echarts
├── font-awesome-4.7.0
├── jQuery
├── jQueryUI
├── jquery-contextmenu
└── exceljs.min.js
```
如果你使用的vue-cli创建的项目,可以参考下面的demo项目
[Demo项目地址]()
## 开始
### 组件注册
```javascript
import IbiComp from '@chuguotech/ibi-vue2-comp';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
// ElementUI
Vue.use(ElementUI);
// 安装IbiComp
Vue.use(IbiComp, {
baseServerUrl: 'http://localhost:8026/cboard' // IBI 服务地址
});
```
### 整合外部vue-i18n
如果您的项目中已经存在i18n国际化配置,可以使用下面办法融合ibi国际化配置
```javascript
import Vue from 'vue'
import VueI18n from 'vue-i18n';
import { enLocale, zhLocale } from '@chuguotech/ibi-vue2-comp'
const messages = {
en: {
...enLocale,
message: {
hello: 'hello world'
}
},
cn: {
...zhLocale,
message: {
hello: '你好世界'
}
}
};
Vue.use(VueI18n);
const i18n = new VueI18n({
locale: 'cn', // 设置地区
messages, // 设置地区信息
});
Vue.use(IbiComp, {
baseServerUrl: 'http://localhost:8026/cboard' // IBI 服务地址
i18n //注册IbiComps时传入i18n对象
});
```
### 整合外部Vuex
如果您的项目中已经存在Vuex, 可以用下面的办法混入ibiStore模块
```javascript
import Vue from 'vue';
import Vuex from 'vuex';
import { ibiStore } from '@chuguotech/ibi-vue2-comp';
Vue.use(Vuex);
const store = Vuex.Store({
state: {
... // 您的项目中原有啊Vuex定义
},
modules: {
...ibiStore.modules // 混入ibiStore模块
}
});
Vue.use(IbiComp, {
baseServerUrl: 'http://localhost:8026/cboard' // IBI 服务地址
store //注册IbiComps时传入store对象
});
```
## IbiChart组件
用来展示IBI中的所有图表
- 支持图表类型包含:交叉表、ECharts图表、KPI、明细表
- 支持参数配置响应
- 支持联动事件
- 支持表格数据下载
```html