uni-app map组件markers的iconPath在app上使用临时路径时图片显示不正常

uni-app map组件markers的iconPath在app上使用临时路径时图片显示不正常

开发环境 版本号 项目创建方式
Windows win10 HBuilderX

操作步骤:

item.coupon.amount = Number(item.coupon.amount)  
let imgurl = item.store_cate.package_icon+'?imageView2/5/w/175/h/175/q/75';  
uni.getImageInfo({  
src:imgurl,  
success(result) {  
console.log(result.path)  
item.iconPath = result.path  
},  
fail(err) {  
    console.log(err,123)  
    uni.showToast({  
            title:"图标加载失败",  
        icon:"none"  
        })  
}  
})  
item.width = 75 //app中不起效  
item.height = 75 //app中不起效  
item.id = item.store_id  
item.latitude = item.store_latitude  
item.longitude = item.store_longitude  

更多关于uni-app map组件markers的iconPath在app上使用临时路径时图片显示不正常的实战教程也可以访问 https://www.itying.com/category-93-b0.html

1 回复

更多关于uni-app map组件markers的iconPath在app上使用临时路径时图片显示不正常的实战教程也可以访问 https://www.itying.com/category-93-b0.html


在uni-app中,map组件的markers使用临时路径作为iconPath时,在App端确实可能遇到图片显示问题。这通常是因为App端对临时路径的处理方式与H5不同。

从你的代码来看,主要问题可能出现在以下几个方面:

  1. 临时路径生命周期问题:App端获取的临时路径可能在某些情况下被系统回收,导致图片无法正常加载。建议将网络图片下载到本地永久路径,或直接使用网络URL。

  2. 尺寸设置不生效:在App端,marker的width和height属性确实存在兼容性问题。可以尝试通过调整图片本身的尺寸来替代设置width和height。

  3. 路径格式问题:确保获取的临时路径是完整的文件路径,可以尝试在路径前加上"file://"前缀。

建议修改方案:

// 直接使用网络图片URL
item.iconPath = imgurl
// 或者下载到本地
// uni.downloadFile({
//   url: imgurl,
//   success: (res) => {
//     item.iconPath = res.tempFilePath
//   }
// })

// 移除width和height设置,通过控制图片尺寸来调整显示大小
回到顶部