mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2025-04-06 03:58:05 +08:00
修复 cell 在元素更新后,边框会不显示的问题 (#236)
This commit is contained in:
parent
0e49ef92ac
commit
18485e2393
@ -1,18 +1,39 @@
|
|||||||
|
let cellUpdateTimeout = 0;
|
||||||
|
|
||||||
Component({
|
Component({
|
||||||
relations: {
|
relations: {
|
||||||
'../cell/index': {
|
'../cell/index': {
|
||||||
type: 'child',
|
type: 'child',
|
||||||
linked() {}
|
linked() {
|
||||||
|
this._updateIsLastCell();
|
||||||
|
},
|
||||||
|
linkChanged() {
|
||||||
|
this._updateIsLastCell();
|
||||||
|
},
|
||||||
|
unlinked() {
|
||||||
|
this._updateIsLastCell();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ready() {
|
|
||||||
let cells = this.getRelationNodes('../cell/index');
|
|
||||||
|
|
||||||
if (cells.length > 0) {
|
methods: {
|
||||||
let lastIndex = cells.length - 1;
|
_updateIsLastCell() {
|
||||||
|
// 用 setTimeout 减少计算次数
|
||||||
|
if (cellUpdateTimeout > 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
cells.forEach((cell, index) => {
|
cellUpdateTimeout = setTimeout(() => {
|
||||||
if (index < lastIndex) cell.notLastCell();
|
cellUpdateTimeout = 0;
|
||||||
|
let cells = this.getRelationNodes('../cell/index');
|
||||||
|
|
||||||
|
if (cells.length > 0) {
|
||||||
|
let lastIndex = cells.length - 1;
|
||||||
|
|
||||||
|
cells.forEach((cell, index) => {
|
||||||
|
cell.updateIsLastCell(index === lastIndex);
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -72,8 +72,10 @@ Component({
|
|||||||
this.navigateTo();
|
this.navigateTo();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
notLastCell() {
|
|
||||||
this.setData({ isLastCell: false });
|
// 用于被 cell-group 更新,标志是否是最后一个 cell
|
||||||
|
updateIsLastCell(isLastCell) {
|
||||||
|
this.setData({ isLastCell });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user