uni-app中【问题及解决方法】uni.getImageInfo 使用本地图片报错errMsg: "getImageInfo:fail file not found"
uni-app中【问题及解决方法】uni.getImageInfo 使用本地图片报错errMsg: “getImageInfo:fail file not found”
开发环境 | 版本号 | 项目创建方式 |
---|---|---|
Windows 10 家庭中文版 | 20H2 | HBuilderX |
iOS | 15 | - |
HBuilderX | 3.1.22 | - |
产品分类:uniapp/App
PC开发环境操作系统:Windows
PC开发环境操作系统版本号:Windows 10 家庭中文版 20H2
HBuilderX类型:正式
HBuilderX版本号:3.1.22
手机系统:iOS
手机系统版本号:iOS 15
手机厂商:苹果
手机机型:苹果11 15.0.1
页面类型:vue
vue版本:vue2
打包方式:云端
项目创建方式:HBuilderX
示例代码:
wx.getImageInfo({
src: 'test.png',
complete: (res) => {
console.log(res)
this.setData({
info: this.format(res)
})
}
})
uni.getImageInfo({
src: 'test.png',
complete: (res) => {
console.log(res)
}
})
操作步骤:
uni.getImageInfo({
src: 'test.png',//使用本地图片
complete: (res) => {
console.log(res)
}
})
更多关于uni-app中【问题及解决方法】uni.getImageInfo 使用本地图片报错errMsg: "getImageInfo:fail file not found"的实战教程也可以访问 https://www.itying.com/category-93-b0.html
请升级至HBuilder X - 3.2.14-alpha版本试下
更多关于uni-app中【问题及解决方法】uni.getImageInfo 使用本地图片报错errMsg: "getImageInfo:fail file not found"的实战教程也可以访问 https://www.itying.com/category-93-b0.html
3.2.16.20211122 可以吗?
HBuilder X - 3.2.14-alpha 好像没看见 更新日志没有看见这个版本的
3.2.16.20211122 试了不行哦 还是一样报错呢
回复 果真zZ: 微信小程序未复现此问题,请提供一个简单可复现的示例(上传附件)
回复 DCloud_UNI_Anne: 看下我底下评论的附件下
这个是附件
图片等静态资源应存放在static目录,注意:静态资源只能存放于此
编译到任意平台时,static 目录下的文件均会被完整打包进去,且不会编译。
详见 文档说明
微信官方是可以,是uni-app 静态资源需要固定位置是吧,我试试
附件中的方法使用图片地址用/static/logo.png 可以解析了 ,感谢
这是一个常见的路径问题,uni.getImageInfo在访问本地图片时需要正确指定图片路径。以下是解决方法:
-
确保图片文件确实存在于项目中,通常应该放在static目录下
-
使用正确的路径格式:
- 绝对路径:
/static/test.png
- 相对路径:
../../static/test.png
- 修改后的代码示例:
uni.getImageInfo({
src: '/static/test.png', // 使用绝对路径
success: (res) => {
console.log('图片信息:', res)
},
fail: (err) => {
console.error('获取失败:', err)
}
})