本人第一次写uniapp,使用了uniapp的外部组件,uni-ui组件库,因为有多张图片上传需求,就使用了里面的图片上传组件uni-file-licker,我使用了以后前端页面可以显示出我所上传的图片,但是我不知道该如何去处理存值以及正确的向后台发起请求,相关文档并没有详细介绍该部分,网络搜索相关问题也大多是原生的上传方法并不能解决我的问题,所以在此发帖请求帮忙解决,如果有该组件使用实例最好不过。
4条回答 默认 最新
- qq_35583629 2022-05-14 22:16关注
<uni-file-picker v-model="imageValue" fileMediatype="image" mode="grid" @select="select" @progress="progress" @success="success" @fail="fail" /> <script> export default { data() { return { imageValue: [] } }, methods: { // 获取上传状态 async select(e) { console.log('选择文件:', e) await this.uploadImg(res.tempFilePaths, 1); }, async uploadImg(tempFilePaths, token) { console.log(token) if (!tempFilePaths.length) return; const path = tempFilePaths.pop(); this.filePathsList.push({ url: path, name: "" }) const [err, { data }] = await uni.uploadFile({ url: 'https://localhost/file/api/uploadtemp', filePath: path, name: 'file', header: { Authorization: token, "Content-Type": "multipart/form-data", } }); console.log("err", err) console.log("data", data) if (!this.isGuid(data)) { // upload fail this.filePathsList.pop() uni.showToast({ title: "上传失败", icon: "none" }) } else { // upload success this.filePathsList[this.filePathsList.length - 1].name = data } this.uploadImg(tempFilePaths, token); }, // 获取上传进度 progress(e) { console.log('上传进度:', e) }, // 上传成功 success(e) { console.log('上传成功') }, // 上传失败 fail(e) { console.log('上传失败:', e) } } } </script>
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 8无用 2
悬赏问题
- ¥170 如图所示配置eNSP
- ¥20 docker里部署springboot项目,访问不到扬声器
- ¥15 netty整合springboot之后自动重连失效
- ¥15 悬赏!微信开发者工具报错,求帮改
- ¥20 wireshark抓不到vlan
- ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
- ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
- ¥15 stata安慰剂检验作图但是真实值不出现在图上
- ¥15 c程序不知道为什么得不到结果
- ¥15 键盘指令混乱情况下的启动盘系统重装