Upload multiple images at once

Need to use uview component library

<u-upload ref="uUploadMultiple" :file-list="fileList" :action="action" accept="image"
			    	:max-size="2 * 1024 * 1024" @oversize="oversize" :sizeType="sizeType" @on-remove="deleteImgs" 
			    	:show-progress="false" :auto-upload="false" max-count="9" width="150" height="150"
			    	@on-choose-complete="afterReadImgs">
			    	</u-upload>
// 文件超出大小限制
			oversize() {
    
    
				uni.showToast({
    
    
					title: "图片最大不能超过2M",
					icon: 'none'
				})
			},
			afterReadImgs(event) {
    
    
				this.formRow.fileList=[]
				this.multipleUpload(this.$refs.uUploadMultiple.lists, 2)
			},
			// 多张图片上传
			multipleUpload(event, type) {
    
    
				let that = this;
				let num = 9;
				console.log(event,"111111");
				event.forEach((item,index) => {
    
    
					if (num === event.length) {
    
    
						uni.showToast({
    
    
							title: '最多上传9张图片',
							icon: 'none'
						})
						return
					}
					num += 1
					if (item.file) {
    
    
						// that.uploadDo(item, type)
						uni.uploadFile({
    
    
							url: that.action,
							filePath: item.file.path,
							// name: 'uploadFile',
							// formData: {
    
    
							// 	user: 'test'
							// },
							success(res) {
    
    
								let resp = JSON.parse(res.data)
								that.formRow.fileList[index]=resp.data.fullurl
							}
						});
					}
				})
			},
			// 执行上传
			uploadDo(event, type) {
    
    
				let that = this;
				
			},
			//删除图片
			deleteImgs(index, lists, name) {
    
    
				if(index=='0'){
    
    
					this.formRow.fileList.shift()
				}else{
    
    
					this.formRow.fileList.splice(index,1);
				}
				
				console.log(index, "index")
				console.log(lists, "lists")
				console.log(name, "name")
				console.log(this.formRow.fileList,"这是数组集合22222");
			},

Guess you like

Origin blog.csdn.net/qq_49552046/article/details/123382853