uni-app uni.chooseFile无法选择文件
uni-app uni.chooseFile无法选择文件
开发环境 | 版本号 | 项目创建方式 |
---|---|---|
Windows | 10 | HBuilderX |
操作步骤:
uni.chooseFile({
count: 6, //默认100
type: 'all',
success: res => {
uni.setStorageSync("flag",false)
},
})
预期结果:
此方法可以使用
实际结果:
uni.chooseFile is not a function
bug描述:
uni.chooseFile({
count: 6, //默认100
type: 'all',
success: res => {
uni.setStorageSync("flag",false)
},
})
报错:
Error in v-on handler: "TypeError: uni.chooseFile is not a function"found in
更多关于uni-app uni.chooseFile无法选择文件的实战教程也可以访问 https://www.itying.com/category-93-b0.html
2 回复
简单的逻辑,运行示例代码hello uni-app能复现你描述的问题吗?
不能的话,你需要排查出来具体你哪个页面,哪部分代码导致的。
你按照正确的排错步骤,高概率会发现是你自己的问题,然后直接解决问题。框架一般不会有超级明显的问题。
如果测试确实发现问题,请在社区发帖(报bug)描述你说的问题。附一个能复现此bug的完整demo。
一旦我们能复现问题,1.会紧急安排修复 2.会给你的社区账号加分(分数越高的用户享,有越高的bug审查和建议采纳的优先权重)
更多社区规则详情:https://ask.dcloud.net.cn/article/38139
更多关于uni-app uni.chooseFile无法选择文件的实战教程也可以访问 https://www.itying.com/category-93-b0.html
这个错误是因为uni.chooseFile
是H5端的API,在非H5环境下不可用。解决方案如下:
- 检查运行环境:
// 判断是否是H5环境
if(uni.getSystemInfoSync().platform === 'h5') {
uni.chooseFile({
count: 6,
type: 'all',
success: res => {
uni.setStorageSync("flag",false)
}
})
} else {
// 非H5环境使用其他API
uni.chooseImage({
count: 6,
success: res => {
uni.setStorageSync("flag",false)
}
})
}
- 或者使用条件编译:
// #ifdef H5
uni.chooseFile({
count: 6,
type: 'all',
success: res => {
uni.setStorageSync("flag",false)
}
})
// #endif
// #ifndef H5
uni.chooseImage({
count: 6,
success: res => {
uni.setStorageSync("flag",false)
}
})
// #endif