Skip to content

Commit

Permalink
fix(swiper): 修复动态修改 height 后组件视图未更新问题 (#2485) (#2625)
Browse files Browse the repository at this point in the history
  • Loading branch information
yi-boide authored Oct 30, 2023
1 parent 1cc4b9f commit 1a17233
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/packages/__VUE/swiper/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,3 +342,17 @@ test('should swiper to swiper after calling to method', async () => {
await sleep(100);
expect(wrapper.vm.page).toBe(1);
});

test('should change props height', async () => {
const wrapper = mount(Swiper, {
props: {
height: 200
}
});
wrapper.setProps({
height: 300
});
await nextTick();
await sleep(100);
expect(wrapper.vm.state.height).toBe(300);
});
12 changes: 12 additions & 0 deletions src/packages/__VUE/swiper/index.taro.vue
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,18 @@ export default create({
watch(
() => props.initPage,
() => {
Taro.nextTick(() => {
init();
});
eventCenter.once((getCurrentInstance() as any).router.onReady, () => {
init();
});
}
);
watch(
() => props.height,
(val) => {
Taro.nextTick(() => {
init(+val);
Expand Down
9 changes: 9 additions & 0 deletions src/packages/__VUE/swiper/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,15 @@ export default create({
}
);
watch(
() => props.height,
() => {
nextTick(() => {
init();
});
}
);
watch(
() => state.children.length,
() => {
Expand Down

0 comments on commit 1a17233

Please sign in to comment.