c***@163.com
c***@163.com
  • 发布:2022-07-18 17:30
  • 更新:2022-11-20 00:58
  • 阅读:1244

uni-app previewImage在微信开发者工具中可以预览,真机调试图片看不到

分类:uni-app

①创建项目

npx degit dcloudio/uni-preset-vue#vite-ts my-vue3-project

②页面

<template>  
  <view class="content">  
    <image class="logo" :src="current" @tap="previewImage(current)" />  
  </view>  
</template>  

<script setup lang="ts">  
const current =  
  "https://vip.hangshida-pd.com:8021/images/2022/07/14/562ac469-ac7b-4105-acc4-9c49e789712b.png";  
const previewImage = (current: string) => {  
  const urls = [  
    "https://vip.hangshida-pd.com:8021/images/2022/07/14/562ac469-ac7b-4105-acc4-9c49e789712b.png",  
    "https://vip.hangshida-pd.com:8021/images/2022/07/14/c329c7c4-5ed4-436d-8381-3f146b2467cc.png",  
    "https://vip.hangshida-pd.com:8021/images/2022/07/14/4216a664-4995-4583-b311-bd70cdf01e70.png",  
  ];  
  uni.previewImage({  
    current,  
    urls,  
    success: (result) => {  
      console.log("result: ", result);  
    },  
    fail: (error) => {  
      console.log("error: ", error);  
    },  
  });  
};  
</script>  

<style>  
.content {  
  display: flex;  
  flex-direction: column;  
  align-items: center;  
  justify-content: center;  
}  

.logo {  
  height: 200rpx;  
  width: 200rpx;  
  margin-top: 200rpx;  
  margin-left: auto;  
  margin-right: auto;  
  margin-bottom: 50rpx;  
}  

</style>  
2022-07-18 17:30 负责人:无 分享
已邀请:
DCloud_UNI_WZF

DCloud_UNI_WZF

测试您提供的代码开发者工具预览就打不开,换了三张网络资源图片是可以的

const current =  
  "https://img2.baidu.com/it/u=1814268193,3619863984&fm=253&fmt=auto&app=138&f=JPEG?w=632&h=500"  
  const urls = [  
    "https://img2.baidu.com/it/u=1814268193,3619863984&fm=253&fmt=auto&app=138&f=JPEG?w=632&h=500",  
    "https://img1.baidu.com/it/u=1966616150,2146512490&fm=253&fmt=auto&app=138&f=JPEG?w=751&h=500",  
    "https://img2.baidu.com/it/u=63249423,2260265143&fm=253&fmt=auto&app=120&f=JPEG?w=889&h=500",  
  ]

请替换图片资源尝试是否可以,如可以,请检查图片资源是否做了访问限制等问题

  • z***@163.com

    遇到了同样的问题,图片存在unicloud的云存储上的,直接使用image可以展示,使用uni.previewImage无法展示,直接使用浏览器也能打开图片

    2022-11-20 00:58

  • DCloud_UNI_WZF

    回复 z***@163.com: 测试微信小程序原生开发是否有问题?如确认框架问题,提供测试工程

    2022-11-20 17:53

z***@163.com

z***@163.com

遇到了同样的问题

该问题目前已经被锁定, 无法添加新回复