Browse Source

fix(imagepreview): fix preview not show

suzigang 3 years ago
parent
commit
bb65b3f4c9

+ 4 - 2
src/packages/__VUE/imagepreview/index.taro.vue

@@ -26,7 +26,7 @@
   </nut-popup>
   </nut-popup>
 </template>
 </template>
 <script lang="ts">
 <script lang="ts">
-import { toRefs, reactive, watch, onMounted, ref } from 'vue';
+import { toRefs, reactive, watch, onMounted } from 'vue';
 import { createComponent } from '../../utils/create';
 import { createComponent } from '../../utils/create';
 import Popup from '../popup/index.taro.vue';
 import Popup from '../popup/index.taro.vue';
 // import Video from '../video/index.vue';
 // import Video from '../video/index.vue';
@@ -127,7 +127,9 @@ export default create({
     };
     };
 
 
     const scaleNow = () => {
     const scaleNow = () => {
-      (state.eleImg as any).style.transform = 'scale(' + state.store.scale + ')';
+      if (state.eleImg != null) {
+        (state.eleImg as any).style.transform = 'scale(' + state.store.scale + ')';
+      }
     };
     };
 
 
     const onTouchStart = (event: any) => {
     const onTouchStart = (event: any) => {

+ 4 - 0
src/packages/__VUE/swiper/index.taro.vue

@@ -392,6 +392,10 @@ export default create({
       if (Taro.getEnv() === 'WEB') {
       if (Taro.getEnv() === 'WEB') {
         init();
         init();
       } else {
       } else {
+        Taro.nextTick(async () => {
+          state.rect = await useTaroRect(container, Taro);
+          state.rect && init();
+        });
         eventCenter.once((getCurrentInstance() as any).router.onReady, () => {
         eventCenter.once((getCurrentInstance() as any).router.onReady, () => {
           init();
           init();
         });
         });

+ 1 - 1
src/packages/utils/useTaroRect/index.ts

@@ -47,7 +47,7 @@ export const useTaroRect = (elementRef: (Element | Window | any) | Ref<Element |
       });
       });
     } else {
     } else {
       const query = Taro.createSelectorQuery();
       const query = Taro.createSelectorQuery();
-      query.select(`#${(element as any).id}`).boundingClientRect();
+      query.select(`#${(element as any).id}`) && query.select(`#${(element as any).id}`).boundingClientRect();
       query.exec(function (res: any) {
       query.exec(function (res: any) {
         resolve(res[0]);
         resolve(res[0]);
       });
       });