uniapp实现表单内多图片上传
注意事项:只有app支持多图片上传,小程序只能一张一张传
需求描述:表单数据和选择的多张照片同时提交,效果如下所示:

话不多说,上代码,前端代码:
<template>
<view>
<u-popup :show="show" @close="close">
<view style="display: flex;">
<view class="form-left">
问题描述
</view>
<view class="form-right">
<textarea auto-height="true" v-model="formData.description" :cursor-spacing="150"></textarea>
</view>
</view>
<view v-show="hasDescription" style="margin-left: 60px;">
<text style="color: #FF3333;font-size: small;">请录入问题描述</text>
</view>
<view style="display: flex;">
<view class="form-left">
照片
</view>
<view style="margin-left: 6px;">
<view style="display: flex;">
<view v-for="(pic,index) in fileList" :key="index">
<image :src="pic.uri" @click="imgPreview(pic)" class="upLoadImg"></image>
</view>
<image v-if="fileList.length < 3" src="../../static/icon/task/upload-pic.png" style="width: 36px;height: 36px;margin: 13px 16px;" @click="selectPics">
</image>
</view>
</view>
</view>
<view style="padding: 20rpx; display: flex;justify-content: space-around;">
<view class="submit-button" @click="submit()">
提交
</view>
<view class="cancel-button" @click="cancel">
取消
</view>
</view>
</u-popup>
<

本文展示了如何在uniapp中实现表单结合多图片上传的功能。前端使用了uni-popup组件创建弹窗表单,通过uni.chooseImage选择图片并上传,利用uni.uploadFile将图片和表单数据发送到后台。后台通过MultipartRequest接收并保存图片。注意,小程序仅支持单张图片上传。
最低0.47元/天 解锁文章
981

被折叠的 条评论
为什么被折叠?



