实现效果:
2023-4-13 修改 []传参数组之对h5有用 app端只取到一张图片
1 2 3 4 5 6 7 8 9
| <u-form-item :label-position="labelPosition" label="上传图片" prop="photo" label-width="150"> <u-upload width="160" height="160" :auto-upload="false" @on-list-change="imageListChange" :source-type="['camera']" ref="uUpload" :custom-btn="true"> <view slot="addBtn" class="slot-btn" hover-class="slot-btn__hover" hover-stay-time="150"> <u-icon name="camera" size="60" color="#606266"></u-icon> <span class="text">拍照上传</span> </view> </u-upload> </u-form-item>
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| imageListChange(lists, name) { this.paramObj.images = [] if (lists.length > 0) { lists.forEach((r, index) => { r.file.uri = r.file.path let obj = {} obj.name = 'image'+index; obj.uri = r.file.path; this.paramObj.images.push(obj) }) } else { this.paramObj.images = [] } },
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| uni.uploadFile({ url: 'xxx', files: this.paramObj.images, name: 'images[]', formData: { 'p_type': this.paramObj.p_type, 'wo_number': this.paramObj.wo_number }, header: {}, success: (res) => { console.log(res); }, fail(error) { console.log(error); }, complete() { uni.hideLoading() } });
|