diff --git a/src/swipe/index.tsx b/src/swipe/index.tsx index d69fbc1e7..caf4722da 100644 --- a/src/swipe/index.tsx +++ b/src/swipe/index.tsx @@ -282,7 +282,9 @@ export default createComponent({ const rect = useRect(root); - active = Math.min(children.length - 1, active); + if (count.value) { + active = Math.min(count.value - 1, active); + } state.rect = rect; state.swiping = true; @@ -430,10 +432,7 @@ export default createComponent({ (value) => initialize(+value) ); - watch( - () => children.length, - () => initialize(state.active) - ); + watch(count, () => initialize(state.active)); watch( () => props.autoplay, diff --git a/src/swipe/test/__snapshots__/index.spec.js.snap b/src/swipe/test/__snapshots__/index.spec.js.snap index 7a762ba3b..68f97cce8 100644 --- a/src/swipe/test/__snapshots__/index.spec.js.snap +++ b/src/swipe/test/__snapshots__/index.spec.js.snap @@ -32,6 +32,44 @@ exports[`should not allow to drag swipe when touchable is false 1`] = ` `; +exports[`should render dynamic SwipeItem correctly 1`] = ` +
+
+
+
+`; + +exports[`should render dynamic SwipeItem correctly 2`] = ` +
+
+
+ + 1 + +
+
+ + 2 + +
+
+
+ + + + +
+
+`; + exports[`should render initial swipe correctly 1`] = `
{ + const wrapper = mount({ + setup() { + const render = ref(false); + onMounted(() => { + render.value = true; + }); + return { render }; + }, + render() { + return ( + + {this.render && [ + + 1 + , + + 2 + , + ]} + + ); + }, + }); + + expect(wrapper.html()).toMatchSnapshot(); + await later(); + expect(wrapper.html()).toMatchSnapshot(); +});