foreword
Learning notes for getting started with vue2 4: Building a vue environment
Reference link: vue2.0 project introduces element-ui
1. Install elment-ui
Enter the built vue project
cd vue_bing_test
install element
npm i element-ui
2. Introduce elment-ui
Change main.js to the following:
import Vue from 'vue'
import App from './App'
import router from './router'
// 引入elemetn-ui组件库
import ElementUI from 'element-ui';
// 引入element-ui全部css
import 'element-ui/lib/theme-default/index.css'
// 使用element
Vue.use(ElementUI)
Vue.config.productionTip = false
/* eslint-disable no-new */
new Vue({
el: '#app',
router,
components: {
App },
template: '<App/>'
})
But there was an error.
Solution:
put
import 'element-ui/lib/theme-default/index.css'
changed to
import 'element-ui/lib/theme-chalk/index.css'
Solved successfully!
3. Use element under src/App.vue
Add to
<el-button type="success">Success</el-button>
The full version is as follows
<template>
<div id="app">
<img src="./assets/logo.png">
<router-view/>
<el-button type="success">Success</el-button>
</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>
4. Run the project to see the effect
npm run dev
The interface
changes from this to this.
Successfully call elment-ui to add a button control!