# 安装cheers-ui

npm install cheers-ui --save
1
cnpm install cheers-ui --save
1

# 按需引入

借助 babel-plugin-component,我们可以只引入需要的组件,以达到减小项目体积的目的。

首先,安装 babel-plugin-component:

npm install babel-plugin-component -D
1

babel.config.js中使用

module.exports = {
        presets: [
                '@vue/app', [
                        '@babel/preset-env', {
                                modules: false
                        }
                ]
        ],
        plugins: [
                [
                        'component',
                        {
                                'libraryName': 'element-ui',
                                'styleLibraryName': 'theme-chalk'
                        }
                ],
                [
                        "import",
                        {
                                "libraryName": "cheers-ui", //组件库名称
                                "camel2DashComponentName": false, //关闭驼峰自动转链式
                                "camel2UnderlineComponentName": false //关闭蛇形自动转链式
                        }
                ],

        ]
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

在main.js中引入

import Vue from 'vue';
import App from './App.vue';
import {
        cheersTable,
        cheersCard,
        cheersFormTitle,
        cheersForm,
        cheersSearchBar,
        cheersPaginations,
        cheersUploadImage,
} from 'cheers-ui'
import "cheers-ui/lib/style/index.css";
Vue.use(cheersTable).use(cheersCard).
use(cheersFormTitle).use(cheersForm).
use(cheersSearchBar).use(cheersPaginations)
.use(cheersUploadImage)

new Vue({
  el: '#app',
  render: h => h(App)
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
更新时间: 7/19/2020, 9:57:25 PM