element-ui按需引入及风格大小设置

文章目录

  • 首先,安装 babel-plugin-component:
npm install babel-plugin-component -D
  • 然后,将 .babelrc 修改为:
{
    
    
  "presets": [["es2015", {
    
     "modules": false }]],
  "plugins": [
    [
      "component",
      {
    
    
        "libraryName": "element-ui",
        "styleLibraryName": "theme-chalk"
      }
    ]
  ]
}
  • 接下来,如果你只希望引入部分组件,比如 Button 和 Select,那么需要在 main.js 中写入以下内容:
import Vue from 'vue';
import {
    
     Button, Select } from 'element-ui';
import App from './App.vue';

Vue.component(Button.name, Button);
Vue.component(Select.name, Select);
/* 或写为
 * Vue.use(Button)
 * Vue.use(Select)
 */

new Vue({
    
    
  el: '#app',
  render: h => h(App)
});
  • 可在main.js中全局设置element-ui风格大小
Vue.prototype.$ELEMENT = {
    
     size: 'small' };

猜你喜欢

转载自blog.csdn.net/qq_44741577/article/details/140824731