element-ui按需引入

1.安装

cnpm i element-ui -S  //-S表示 --save

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

npm install babel-plugin-component -D 

2.1 在.bable.js天下如下配置

{
  "presets": [
    ["es2015", { "modules": false }]
  ],
  "plugins": [["component", [
    {
      "libraryName": "element-ui",
      "styleLibraryName": "theme-chalk"
    }
  ]]]
}

3 .安装es2015

cnpm install babel-preset-es2015 --save-dev 

4.在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)
	})

你可能感兴趣的:(vue2.0)