panel-group
日月幾何,天地玄黃,今日奇觀,書接上一回。
這次我們來講<panel-group />
組件
因?yàn)楸疚氖歉?xiàng)目來的,所以不從第一篇看起的小伙伴云里霧里,所以針對(duì)以上情況,我決定對(duì)于vue-element-admin
項(xiàng)目出現(xiàn)的大部分技術(shù)棧以及知識(shí)點(diǎn)(比如:element-ui,echarts,vuex等等)進(jìn)行講解與實(shí)操。跟著項(xiàng)目學(xué)習(xí)是非常有效率的,但把項(xiàng)目中學(xué)到的知識(shí)點(diǎn),自己再對(duì)著官網(wǎng)的API進(jìn)行擴(kuò)展更能加強(qiáng)和鞏固。當(dāng)然,是在另一個(gè)專欄中
el-row與el-col
代碼有點(diǎn)多。
<template>
<el-row :gutter="40" class="panel-group">
<el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
<div class="card-panel" @click="handleSetLineChartData('newVisitis')">
<div class="card-panel-icon-wrapper icon-people">
<svg-icon icon-class="peoples" class-name="card-panel-icon" />
</div>
<div class="card-panel-description">
<div class="card-panel-text">
New Visits
</div>
<count-to :start-val="0" :end-val="102400" :duration="2600" class="card-panel-num" />
</div>
</div>
</el-col>
<el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
<div class="card-panel" @click="handleSetLineChartData('messages')">
<div class="card-panel-icon-wrapper icon-message">
<svg-icon icon-class="message" class-name="card-panel-icon" />
</div>
<div class="card-panel-description">
<div class="card-panel-text">
Messages
</div>
<count-to :start-val="0" :end-val="81212" :duration="3000" class="card-panel-num" />
</div>
</div>
</el-col>
<el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
<div class="card-panel" @click="handleSetLineChartData('purchases')">
<div class="card-panel-icon-wrapper icon-money">
<svg-icon icon-class="money" class-name="card-panel-icon" />
</div>
<div class="card-panel-description">
<div class="card-panel-text">
Purchases
</div>
<count-to :start-val="0" :end-val="9280" :duration="3200" class="card-panel-num" />
</div>
</div>
</el-col>
<el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
<div class="card-panel" @click="handleSetLineChartData('shoppings')">
<div class="card-panel-icon-wrapper icon-shopping">
<svg-icon icon-class="shopping" class-name="card-panel-icon" />
</div>
<div class="card-panel-description">
<div class="card-panel-text">
Shoppings
</div>
<count-to :start-val="0" :end-val="13600" :duration="3600" class="card-panel-num" />
</div>
</div>
</el-col>
</el-row>
</template>
<script>
import CountTo from 'vue-count-to'
export default {
components: {
CountTo
},
methods: {
handleSetLineChartData(type) {
this.$emit('handleSetLineChartData', type)
}
}
}
</script>
<style lang="scss" scoped>
.panel-group {
margin-top: 18px;
.card-panel-col {
margin-bottom: 32px;
}
.card-panel {
height: 108px;
cursor: pointer;
font-size: 12px;
position: relative;
overflow: hidden;
color: #666;
background: #fff;
box-shadow: 4px 4px 40px rgba(0, 0, 0, .05);
border-color: rgba(0, 0, 0, .05);
&:hover {
.card-panel-icon-wrapper {
color: #fff;
}
.icon-people {
background: #40c9c6;
}
.icon-message {
background: #36a3f7;
}
.icon-money {
background: #f4516c;
}
.icon-shopping {
background: #34bfa3
}
}
.icon-people {
color: #40c9c6;
}
.icon-message {
color: #36a3f7;
}
.icon-money {
color: #f4516c;
}
.icon-shopping {
color: #34bfa3
}
.card-panel-icon-wrapper {
float: left;
margin: 14px 0 0 14px;
padding: 16px;
transition: all 0.38s ease-out;
border-radius: 6px;
}
.card-panel-icon {
float: left;
font-size: 48px;
}
.card-panel-description {
float: right;
font-weight: bold;
margin: 26px;
margin-left: 0px;
.card-panel-text {
line-height: 18px;
color: rgba(0, 0, 0, 0.45);
font-size: 16px;
margin-bottom: 12px;
}
.card-panel-num {
font-size: 20px;
}
}
}
}
@media (max-width:550px) {
.card-panel-description {
display: none;
}
.card-panel-icon-wrapper {
float: none !important;
width: 100%;
height: 100%;
margin: 0 !important;
.svg-icon {
display: block;
margin: 14px auto !important;
float: none !important;
}
}
}
</style>
這里首先就用到了element-ui的layout布局,使用el-row
和el-col
并通過它們的屬性來實(shí)現(xiàn)組件的布局。element-ui將整個(gè)頁面柵格化,而el-row表示一行,el-col表示列,element-ui一共有24個(gè)列el-row
的:gutter屬性設(shè)置了行內(nèi)各列之間的間隔,默認(rèn)為0,這個(gè)屬性會(huì)在子元素el-col
的左右兩邊以padding的形式添加,比如上述的:gutter值為40,那么,每個(gè)el-col
兩邊都會(huì)出現(xiàn)20px的padding。el-col
中的:xs :sm :lg等屬性指定了當(dāng)頁面寬度改變時(shí),el-col占多少柵格,因?yàn)榧词鬼撁鎸挾茸冃?,其依舊可以分為24格。
vue-count-to
這是一個(gè)Vue.js組件,用于實(shí)現(xiàn)數(shù)字的動(dòng)態(tài)增加或減少的效果。你可以通過設(shè)置startVal(開始值)和endVal(結(jié)束值)來控制數(shù)字的起始和結(jié)束值。此外,你還可以設(shè)置duration(持續(xù)時(shí)間)來控制動(dòng)畫的持續(xù)時(shí)間。
$emit()的妙用
可以看到methods里有一個(gè)點(diǎn)擊事件
//admin文件夾下components下的panel-group.vue
methods: {
handleSetLineChartData(type) {
this.$emit('handleSetLineChartData', type)
}
}
this.$emit(‘event’, params)是一種常見的模式,用于子組件向父組件發(fā)送事件。這里的this.$emit是一個(gè)方法,它可以觸發(fā)一個(gè)自定義事件,并將這個(gè)事件發(fā)送到父組件。其接收兩個(gè)參數(shù)
- 'event’是你想要觸發(fā)的事件的名稱。
- 'params’是你想要傳遞給事件處理器的參數(shù)。
//admin文件夾下的index.vue
data() {
return {
lineChartData: lineChartData.newVisitis
}
},
methods: {
// 這個(gè)type可以是newVisitis或messages或purchases或Sshoppings
// 由子組件PanelGroup使用$emit()方法向父組件發(fā)送事件
handleSetLineChartData(type) {
this.lineChartData = lineChartData[type]
}
}
//admin文件夾下的index.vue
const lineChartData = {
newVisitis: {
expectedData: [100, 120, 161, 134, 105, 160, 165],
actualData: [120, 82, 91, 154, 162, 140, 145]
},
messages: {
expectedData: [200, 192, 120, 144, 160, 130, 140],
actualData: [180, 160, 151, 106, 145, 150, 130]
},
purchases: {
expectedData: [80, 100, 121, 104, 105, 90, 100],
actualData: [120, 90, 100, 138, 142, 130, 130]
},
shoppings: {
expectedData: [130, 140, 141, 142, 145, 150, 160],
actualData: [120, 82, 91, 154, 162, 140, 130]
}
}
在子組件中觸發(fā)不同的點(diǎn)擊事件,通過this.$emit()將點(diǎn)擊事件和參數(shù)提供給父組件,父組件獲得后,根據(jù)參數(shù)的不同渲染lineChartData中的數(shù)據(jù)。文章來源:http://www.zghlxwxcb.cn/news/detail-786971.html
style元素雜談
- lang=“scss”:SCSS是CSS預(yù)處理器SASS的一種語法,它允許你使用變量、嵌套規(guī)則、混合、函數(shù)等高級(jí)功能來編寫更加清晰、易于維護(hù)的CSS。
- scoped:scoped屬性指定了樣式表的作用范圍。當(dāng)一個(gè)style標(biāo)簽有scoped屬性時(shí),它的CSS只會(huì)應(yīng)用到當(dāng)前組件的元素。這可以防止樣式?jīng)_突,使得每個(gè)組件的樣式都是獨(dú)立的
- &:其代表父選擇器的引用。在SCSS中,它通常用于嵌套規(guī)則
- @media (max-width:550px):{}是CSS中的一個(gè)媒體查詢。這個(gè)查詢會(huì)應(yīng)用在屏幕寬度小于或等于550像素的設(shè)備上
- float:none !important;:這個(gè)聲明表示元素不進(jìn)行浮動(dòng),并且這個(gè)聲明的權(quán)重很高,會(huì)覆蓋其他任何關(guān)于float的聲明
本組件中還有svg-icon
元素沒有講解到,大家可以去看看這個(gè)人的文章https://blog.csdn.net/qq_39246667/article/details/124347398文章來源地址http://www.zghlxwxcb.cn/news/detail-786971.html
到了這里,關(guān)于【vue-element-admin】github高質(zhì)量vue項(xiàng)目解讀,小白都能看懂(第三篇)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!