使用之前当然要先下载Element Plus
网址:element安装
使用npm安装:
#先把npm镜像改为国内的
npm install -g cnpm --registry=https://registry.npm.taobao.org
#然后再下载就会快上许多
cnpm install element-plus --save
使用yarn安装(个人感觉更喜欢yarn):
#先把npm镜像改为国内的
npm install -g cnpm --registry=https://registry.npm.taobao.org
#然后用cnpm安装yarn
cnpm install -g yarn
#把yarn镜像改为国内的
yarn config set registry https://registry.npm.taobao.org/
#然后再用yarn下载
yarn add element-plus
开始使用:
<template>
<el-row>
<el-button plain>Plain</el-button>
<el-button type="primary" plain>Primary</el-button>
<el-button type="success" plain>Success</el-button>
<el-button type="info" plain>Info</el-button>
<el-button type="warning" plain>Warning</el-button>
<el-button type="danger" plain>Danger</el-button>
</el-row>
</template>
<script>
import { ElButton,ElRow } from 'element-plus'
export default {
components:{
ElButton,
ElRow
}
}
</script>
但是却发现浏览器给的效果是这样的:
解决方案(在main.js文件中加入一句import 'element-plus/theme-chalk/index.css'就好了):
import { createApp } from 'vue'
import App from './App.vue'
import 'element-plus/theme-chalk/index.css'
let app=createApp(App)
app.mount('#app')
解决后的效果:
其实也可以直接在main.js把要用的组件都引好,到后面就不需要一个一个文件的引入了:
import { createApp } from 'vue'
import App from './App.vue'
import 'element-plus/theme-chalk/index.css'
import { ElButton,ElRow } from 'element-plus'
let app=createApp(App)
app.use(ElButton,ElRow)
app.mount('#app')
使用的文件就可以这样写:
<template>
<el-row>
<el-button plain>Plain</el-button>
<el-button type="primary" plain>Primary</el-button>
<el-button type="success" plain>Success</el-button>
<el-button type="info" plain>Info</el-button>
<el-button type="warning" plain>Warning</el-button>
<el-button type="danger" plain>Danger</el-button>
</el-row>
</template>
<script>
</script>
效果是一样的:
我知道可能确实有点啰嗦了,本来就是一句话的事,非要扯那么多,第一次写博客,还请勿喷!