1、首先初始一个vue项目并安装element ui
vue init webpack-simple element-demo
cd element-demo
npm install
cnpm install element-ui -S
npm run dev
2、编辑main.js引入element ui (引入后就可以使用element中的样式了)
main.js:
import Vue from 'vue'
import ElementUI from 'element-ui'; // 引入element-ui
import 'element-ui/lib/theme-chalk/index.css'; // element-ui的css样式要单独引入
import App from './App.vue'
Vue.use(ElementUI); // 这种方式引入了ElementUI中所有的组件
new Vue({
el: '#app',
render: h => h(App)
})
3、在webpack.config.js中添加loader
webpack.config.js:
var path = require('path')
var webpack = require('webpack')
module.exports = {
entry: './src/main.js',
output: {
path: path.resolve(__dirname, './dist'),
publicPath: '/dist/',
filename: 'build.js'
},
module: {
rules: [
{
test: /\.css$/,
use: [
'vue-style-loader',
'css-loader'
],
}, {
test: /\.vue$/,
loader: 'vue-loader',
options: {
loaders: {
}
// other vue-loader options go here
}
},
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
},
{
test: /\