Skip to content

Commit

Permalink
fix: 完善pi-grid-item最后一列的判断
Browse files Browse the repository at this point in the history
feat: index属性注释写明必须从0开始
  • Loading branch information
sadais-lwt committed Aug 16, 2021
1 parent 770cee1 commit 12afd9a
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions components/pi-grid-item/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default {
return gridItem.customClass
}
},
// 当前宫格索引
// 当前宫格索引;必须从0开始
index: {
type: [Number, String],
required: true
Expand Down Expand Up @@ -129,6 +129,12 @@ export default {
getHoverClass() {
return this.inheritProps.hoverClass !== null ? this.inheritProps.hoverClass : this.hoverClass
},
isLastCol() {
// 是否是最后一列
const idx = parseInt(this.index, 10)
const totalCol = this.getCol
return idx + 1 === totalCol
},
itemStyle() {
const gap = this.$pi.common.addUnit(this.getGap)
const style = {
Expand All @@ -137,7 +143,7 @@ export default {
marginBottom: gap
}
// 如果设置了index,并且是列数的最后一行,则不设置marginRight
if (this.index && (this.index + 1) % this.getCol === 0) {
if (this.isLastCol) {
style.marginRight = 0
}
if (this.bgColor) style.backgroundColor = this.bgColor
Expand Down

0 comments on commit 12afd9a

Please sign in to comment.