Skip to content

Commit bc97977

Browse files
committed
fix(action-sheet): refactor initialization and observer for items update
1 parent 024269b commit bc97977

File tree

1 file changed

+24
-16
lines changed

1 file changed

+24
-16
lines changed

src/action-sheet/action-sheet.ts

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,27 @@ export default class ActionSheet extends SuperComponent {
3636
},
3737
];
3838

39+
observers = {
40+
items() {
41+
this.init();
42+
},
43+
};
44+
3945
ready() {
40-
this.memoInitialData();
41-
this.splitGridThemeActions();
46+
this.init();
4247
}
4348

4449
methods = {
45-
onSwiperChange(e: WechatMiniprogram.TouchEvent) {
46-
const {
47-
detail: { current },
48-
} = e;
49-
this.setData({
50-
currentSwiperIndex: current,
51-
});
50+
init() {
51+
this.memoInitialData();
52+
this.splitGridThemeActions();
53+
},
54+
55+
memoInitialData() {
56+
this.initialData = {
57+
...this.properties,
58+
...this.data,
59+
};
5260
},
5361

5462
splitGridThemeActions() {
@@ -70,13 +78,6 @@ export default class ActionSheet extends SuperComponent {
7078
this._trigger('visible-change', { visible: true });
7179
},
7280

73-
memoInitialData() {
74-
this.initialData = {
75-
...this.properties,
76-
...this.data,
77-
};
78-
},
79-
8081
/** 指令调用隐藏 */
8182
close() {
8283
this.triggerEvent('close', { trigger: 'command' });
@@ -95,6 +96,13 @@ export default class ActionSheet extends SuperComponent {
9596
}
9697
},
9798

99+
onSwiperChange(e: WechatMiniprogram.TouchEvent) {
100+
const { current } = e.detail;
101+
this.setData({
102+
currentSwiperIndex: current,
103+
});
104+
},
105+
98106
onSelect(event: WechatMiniprogram.TouchEvent) {
99107
const { currentSwiperIndex, items, gridThemeItems, count, theme } = this.data;
100108
const { index } = event.currentTarget.dataset;

0 commit comments

Comments
 (0)