Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(swiper): 在动态修改height值后,组件视图未更新 (#2485) #2625

Merged
merged 4 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 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,16 @@ 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();
expect(wrapper.vm.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 @@ -433,6 +433,18 @@ export default create({
}
);

watch(
() => props.height,
(val) => {
Taro.nextTick(() => {
init(+val);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

调用 init 方法的参数需要修改

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

修改成什么呢?我看其他watch也是这样的

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

修改成什么呢?我看其他watch也是这样的

init 方法的参数是激活 swiper-item 的下标,height 的变化不涉及它的变动,应该传空

});
eventCenter.once((getCurrentInstance() as any).router.onReady, () => {
init(+val);
});
}
);

watch(
() => state.children.length,
() => {
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,
(val) => {
nextTick(() => {
init(Number(val));
});
}
);

watch(
() => state.children.length,
() => {
Expand Down