element ui是杰出的组件库,目前已经被广泛使用于vue2.x版本中,简单介绍一下全局使用elementUI

  • 引入element UI模块
npm i element-ui -S
  • 在main.js中引入element ui组件和样式
// 导入组件
import Element from 'element-ui'
// 导入样式
import 'element-ui/lib/theme-chalk/index.css'
Vue.use(Element)
  • 在需要的组件中引入elementUI (以下以按钮组件为例)
<el-row>
<el-button>默认按钮</el-button>
<el-button type="primary">主要按钮</el-button>
<el-button type="success">成功按钮</el-button>
<el-button type="info">信息按钮</el-button>
<el-button type="warning">警告按钮</el-button>
<el-button type="danger">危险按钮</el-button>
</el-row>

main.js

import Vue from 'vue'
import App from './App'
import router from './router'
// 导入组件
import Element from 'element-ui'
// 导入样式
import 'element-ui/lib/theme-chalk/index.css'
Vue.use(Element)

Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
el: '#app',
router,
components: { App },
template: '<App/>'
})

App.vue

<template>
<div id="app">
<img src="./assets/logo.png">
<el-row>
<el-button>默认按钮</el-button>
<el-button type="primary">主要按钮</el-button>
<el-button type="success">成功按钮</el-button>
<el-button type="info">信息按钮</el-button>
<el-button type="warning">警告按钮</el-button>
<el-button type="danger">危险按钮</el-button>
</el-row>
<router-view/>
</div>
</template>

<script>
export default {
name: 'App'
}
</script>

<style>
#app {
font-family: 'Avenir', Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>
效果图

午夜与element-ui邂逅_前端