|
|
@@ -38,8 +38,6 @@
|
|
|
|
|
|
<script lang="ts">
|
|
|
import {
|
|
|
- onMounted,
|
|
|
- onActivated,
|
|
|
onDeactivated,
|
|
|
onBeforeUnmount,
|
|
|
provide,
|
|
|
@@ -47,7 +45,6 @@ import {
|
|
|
ComponentPublicInstance,
|
|
|
reactive,
|
|
|
computed,
|
|
|
- nextTick,
|
|
|
ref,
|
|
|
watch
|
|
|
} from 'vue';
|
|
|
@@ -55,7 +52,7 @@ import { createComponent } from '@/packages/utils/create';
|
|
|
import { useTouch } from './use-touch';
|
|
|
import { useTaroRect } from '@/packages/utils/useTaroRect';
|
|
|
import { useExpose } from '@/packages/utils/useExpose/index';
|
|
|
-import Taro, { eventCenter, getCurrentInstance, useReady } from '@tarojs/taro';
|
|
|
+import Taro, { eventCenter, getCurrentInstance } from '@tarojs/taro';
|
|
|
const { create, componentName } = createComponent('swiper');
|
|
|
export default create({
|
|
|
props: {
|
|
|
@@ -319,15 +316,17 @@ export default create({
|
|
|
const init = async (active: number = +props.initPage) => {
|
|
|
stopAutoPlay();
|
|
|
state.rect = await useTaroRect(container, Taro);
|
|
|
- active = Math.min(childCount.value - 1, active);
|
|
|
- state.width = props.width ? +props.width : (state.rect as DOMRect).width;
|
|
|
- state.height = props.height ? +props.height : (state.rect as DOMRect).height;
|
|
|
- state.active = active;
|
|
|
- state.offset = getOffset(state.active);
|
|
|
- state.moving = true;
|
|
|
- getStyle();
|
|
|
+ if (state.rect) {
|
|
|
+ active = Math.min(childCount.value - 1, active);
|
|
|
+ state.width = props.width ? +props.width : (state.rect as DOMRect).width;
|
|
|
+ state.height = props.height ? +props.height : (state.rect as DOMRect).height;
|
|
|
+ state.active = active;
|
|
|
+ state.offset = getOffset(state.active);
|
|
|
+ state.moving = true;
|
|
|
+ getStyle();
|
|
|
|
|
|
- autoplay();
|
|
|
+ autoplay();
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
const onTouchStart = (e: TouchEvent) => {
|
|
|
@@ -388,30 +387,6 @@ export default create({
|
|
|
to
|
|
|
});
|
|
|
|
|
|
- onMounted(() => {
|
|
|
- if (Taro.getEnv() === 'WEB') {
|
|
|
- init();
|
|
|
- } else {
|
|
|
- Taro.nextTick(async () => {
|
|
|
- state.rect = await useTaroRect(container, Taro);
|
|
|
- state.rect && init();
|
|
|
- });
|
|
|
- eventCenter.once((getCurrentInstance() as any).router.onReady, () => {
|
|
|
- init();
|
|
|
- });
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- onActivated(() => {
|
|
|
- if (Taro.getEnv() === 'WEB') {
|
|
|
- init();
|
|
|
- } else {
|
|
|
- eventCenter.once((getCurrentInstance() as any).router.onReady, () => {
|
|
|
- init();
|
|
|
- });
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
onDeactivated(() => {
|
|
|
stopAutoPlay();
|
|
|
});
|
|
|
@@ -423,6 +398,9 @@ export default create({
|
|
|
watch(
|
|
|
() => props.initPage,
|
|
|
(val) => {
|
|
|
+ Taro.nextTick(() => {
|
|
|
+ init(+val);
|
|
|
+ });
|
|
|
eventCenter.once((getCurrentInstance() as any).router.onReady, () => {
|
|
|
init(+val);
|
|
|
});
|
|
|
@@ -432,8 +410,13 @@ export default create({
|
|
|
watch(
|
|
|
() => state.children.length,
|
|
|
() => {
|
|
|
+ Taro.nextTick(() => {
|
|
|
+ init();
|
|
|
+ });
|
|
|
eventCenter.once((getCurrentInstance() as any).router.onReady, () => {
|
|
|
- init(state.active);
|
|
|
+ Taro.nextTick(() => {
|
|
|
+ init();
|
|
|
+ });
|
|
|
});
|
|
|
}
|
|
|
);
|