Skip to content

Commit 7c3dbd4

Browse files
committed
feat: 收敛到 swiper 中修改
1 parent 33e8977 commit 7c3dbd4

File tree

2 files changed

+27
-32
lines changed

2 files changed

+27
-32
lines changed

src/packages/__VUE/imagepreview/index.vue

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
:init-page="initNo"
1919
:pagination-visible="paginationVisible"
2020
:pagination-color="paginationColor"
21-
:height="rootHeight"
2221
@change="setActive"
2322
>
2423
<image-preview-item
@@ -45,7 +44,7 @@
4544
</nut-popup>
4645
</template>
4746
<script lang="ts">
48-
import { toRefs, reactive, watch, onMounted, onUnmounted, ref, computed, nextTick } from 'vue'
47+
import { toRefs, reactive, watch, onMounted, ref, computed, nextTick } from 'vue'
4948
import type { PropType } from 'vue'
5049
import { createComponent } from '@/packages/utils/create'
5150
import { isArray } from '@/packages/utils/util'
@@ -114,21 +113,6 @@ export default create({
114113
return props.images
115114
})
116115
117-
// 横竖屏切换
118-
const width = ref(window.innerWidth)
119-
const height = ref(window.innerHeight)
120-
const updateDimensions = () => {
121-
width.value = window.innerWidth
122-
height.value = window.innerHeight
123-
}
124-
125-
// 监听 width 和 height 的变化
126-
watch([width, height], () => {
127-
nextTick(() => {
128-
init()
129-
})
130-
})
131-
132116
// 设置当前选中第几个
133117
const setActive = (active: number) => {
134118
if (active !== state.active) {
@@ -181,12 +165,6 @@ export default create({
181165
182166
onMounted(() => {
183167
setActive(props.initNo)
184-
window.addEventListener('resize', updateDimensions)
185-
updateDimensions() // 初始化尺寸
186-
})
187-
188-
onUnmounted(() => {
189-
window.removeEventListener('resize', updateDimensions)
190168
})
191169
192170
return {

src/packages/__VUE/swiper/index.vue

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ import {
3636
nextTick,
3737
ref,
3838
watch,
39+
onMounted,
40+
onUnmounted,
3941
VNode
4042
} from 'vue'
4143
import { createComponent } from '@/packages/utils/create'
@@ -426,15 +428,6 @@ export default create({
426428
}
427429
)
428430
429-
watch(
430-
() => window.innerHeight < window.innerWidth,
431-
() => {
432-
nextTick(() => {
433-
init()
434-
})
435-
}
436-
)
437-
438431
watch(
439432
() => state.children.length,
440433
() => {
@@ -451,6 +444,30 @@ export default create({
451444
}
452445
)
453446
447+
// 横竖屏切换
448+
const width = ref(window.innerWidth)
449+
const height = ref(window.innerHeight)
450+
const updateDimensions = () => {
451+
width.value = window.innerWidth
452+
height.value = window.innerHeight
453+
}
454+
455+
// 监听 width 和 height 的变化
456+
watch([width, height], () => {
457+
nextTick(() => {
458+
init()
459+
})
460+
})
461+
462+
onMounted(() => {
463+
window.addEventListener('resize', updateDimensions)
464+
updateDimensions() // 初始化尺寸
465+
})
466+
467+
onUnmounted(() => {
468+
window.removeEventListener('resize', updateDimensions)
469+
})
470+
454471
return {
455472
state,
456473
classesInner,

0 commit comments

Comments
 (0)