Skip to content

Commit 32d0d9b

Browse files
二一7insummer
authored andcommitted
fix:修复segment设置activeKey时不更新状态问题 (#656)
1 parent 089b65b commit 32d0d9b

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

dist/segment/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,20 @@ Component({
7575
itemWidth: Number
7676
},
7777

78+
observers: {
79+
'activeKey': function (newKey) {
80+
if(!newKey) return;
81+
const index = this.data.tabList.findIndex(tab=>tab.key===newKey);
82+
this.setData({
83+
currentIndex:index
84+
},() => {
85+
if (this.data.scrollable) {
86+
this.queryMultipleNodes();
87+
}
88+
});
89+
}
90+
},
91+
7892
/**
7993
* 组件的初始数据
8094
*/

examples/dist/segment/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,20 @@ Component({
7575
itemWidth: Number
7676
},
7777

78+
observers: {
79+
'activeKey': function (newKey) {
80+
if(!newKey) return;
81+
const index = this.data.tabList.findIndex(tab=>tab.key===newKey);
82+
this.setData({
83+
currentIndex:index
84+
},() => {
85+
if (this.data.scrollable) {
86+
this.queryMultipleNodes();
87+
}
88+
});
89+
}
90+
},
91+
7892
/**
7993
* 组件的初始数据
8094
*/

src/segment/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,20 @@ Component({
7575
itemWidth: Number
7676
},
7777

78+
observers: {
79+
'activeKey': function (newKey) {
80+
if(!newKey) return;
81+
const index = this.data.tabList.findIndex(tab=>tab.key===newKey);
82+
this.setData({
83+
currentIndex:index
84+
},() => {
85+
if (this.data.scrollable) {
86+
this.queryMultipleNodes();
87+
}
88+
});
89+
}
90+
},
91+
7892
/**
7993
* 组件的初始数据
8094
*/

0 commit comments

Comments
 (0)