1. 程式人生 > 其它 >ElementUI按需引入各種元件

ElementUI按需引入各種元件

1.安裝element-ui

npm i element-ui -S

2.安裝按需引入必要外掛

npm install babel-plugin-component -D

3.修改.babelrc 如果是vueCli3 則修改babel.config.js

module.exports = {
  "presets": [
    '@vue/cli-plugin-babel/preset'
  ],
  "plugins": [
    [
      "component",
      {
        "libraryName": "element-ui",
        "
styleLibraryName": "theme-chalk" } ] ] }

4.在src目錄下新建一個資料夾element,在該目錄下新建index.js

5.在src/element/index.js中按需寫

    import {
        Select,
        Option,
        OptionGroup,
        Input,
        InputNumber,
        Radio,
        Tree,
        Dialog,
        Row,
        Col,
        Checkbox,
        CheckboxButton,
        CheckboxGroup,
        Cascader,
        Switch,
        Slider,
        TimeSelect,
        TimePicker,
        DatePicker,
        Upload,
        Rate,
        ColorPicker,
        Transfer,
        Form,
        FormItem,
        Table,
        TableColumn,
        Tag,
        Button,
        Progress,
        Pagination,
        Badge,
        Avatar,
        Alert,
        Loading,
        Message,
        MessageBox,
        Notification,
        Menu,
        MenuItemGroup,
        MenuItem,
        Submenu,
        RadioGroup,
        RadioButton
    
    } 
from 'element-ui' const element = { install: function(Vue) { Vue.use(Select) Vue.use(Option) Vue.use(OptionGroup) Vue.use(Input) Vue.use(InputNumber) Vue.use(Radio) Vue.use(Tree) Vue.use(Dialog) Vue.use(Row) Vue.use(Col) Vue.use(Checkbox) Vue.use(CheckboxButton) Vue.use(CheckboxGroup) Vue.use(Cascader) Vue.use(Switch) Vue.use(Slider) Vue.use(TimePicker) Vue.use(TimeSelect) Vue.use(DatePicker) Vue.use(Upload) Vue.use(Rate) Vue.use(ColorPicker) Vue.use(Transfer) Vue.use(Form) Vue.use(FormItem) Vue.use(Table) Vue.use(TableColumn) Vue.use(Tag) Vue.use(Button) Vue.use(Progress) Vue.use(Pagination) Vue.use(Badge) Vue.use(Avatar) Vue.use(Alert) Vue.use(Loading) Vue.use(Menu) Vue.use(MenuItem) Vue.use(MenuItemGroup) Vue.use(Submenu) Vue.use(RadioGroup) Vue.use(RadioButton) Vue.prototype.$message
= Message; Vue.prototype.$confirm = MessageBox.confirm; Vue.prototype.$alert = MessageBox.alert; Vue.prototype.$notify = Notification; } } export default element

6.在main.js中寫入

import 'element-ui/lib/theme-chalk/index.css'
import element from './element/index'
Vue.use(element)