Getting Started with Vue2 Study Notes 5: Calling elment-ui in the vue2 project

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

insert image description here

2. Introduce elment-ui

elment official tutorial

insert image description here
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.
insert image description here
Solution:
put

import 'element-ui/lib/theme-default/index.css'

changed to

import 'element-ui/lib/theme-chalk/index.css'

Solved successfully!
insert image description here

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
insert image description here
changes from this to this.
insert image description here
Successfully call elment-ui to add a button control!

Guess you like

Origin blog.csdn.net/qq_34885993/article/details/131771853