uview多图上传


<u-form-item label="上传图片" label-width="150">
    	<u-upload ref="uUploadMultiple" :file-list="multipleImgs" :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>
</u-form-item>

export default { 		
	  data() { 			
			return {
   				multipleImgs: [], // 多张图片
   				sizeType: ['compressed'],
   				 },
       methods: {
			// 文件超出大小限制
			oversize() {
				uni.showToast({
					title: "图片最大不能超过2M",
					icon: 'none'
				})
			},
			afterReadImgs(event) {
				this.multipleUpload(this.$refs.uUploadMultiple.lists, 2)
			},
			// 多张图片上传
			multipleUpload(event, type) {
				let that = this;
				let num = 9;
				event.map(item => {
					if (num === event.length) {
						uni.showToast({
							title: '最多上传9张图片',
							icon: 'none'
						})
						return
					}
					num += 1
					if (item.file) {
						that.uploadDo(item, type)
					}
				})
			},
			// 执行上传
			uploadDo(event, type) {
				let that = this;
				console.log(that.Api.baseURL)
				uni.uploadFile({
					url: that.Api.baseURL + 'common/client/upload',
					filePath: event.file.path,
					// name: 'uploadFile',
					// formData: {
					// 	user: 'test'
					// },
					success(res) {
						console.log(res, "2112121212121")
						let resp = JSON.parse(res.data)
						
					}
				});
			},
			//删除图片
			deleteImgs(index, lists, name) {
				console.log(index, "index")
				console.log(lists, "lists")
				console.log(name, "name")
			},
		}

  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 7
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值