午夜与element-ui邂逅
原创
©著作权归作者所有:来自51CTO博客作者不秃头的小李同学的原创作品,请联系作者获取转载授权,否则将追究法律责任
element ui是杰出的组件库,目前已经被广泛使用于vue2.x版本中,简单介绍一下全局使用elementUI
- 在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>
效果图