uniapp上传和长按删除图片

该博客详细介绍了如何在uni-app中实现图片上传和删除功能。通过`uni.chooseImage`选择图片,限制最多上传6张,并使用`uni.uploadFile`将图片上传到服务器。当用户触摸图片时,会显示删除确认弹窗,点击确认则从数组中移除图片。博客涉及前端开发中的图片处理和用户交互技术。
摘要由CSDN通过智能技术生成
<view class="upload" v-for="(item, index) in list" :key="item">
		<image :src="item" mode="" style="margin-right: 36rpx;" @touchstart.prevent="touchstart(index)"
			@touchend.prevent="touchend">
	</image>
</view>```

js代码
1.上传
		// 拍照
			getPotohos() {
				var _this = this;
				if (_this.list.length >= 6) {
					return _this.$.toast("最多只能上传6张")
				}
				uni.chooseImage({
					count: 6,
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
					sourceType: ['album', 'camera'], //从相册选择
					success: function(chooseImageRes) {
						console.log("img1", chooseImageRes);
						for (let i = 0; i < chooseImageRes.tempFilePaths.length; i++) {
							let tempFilePaths = chooseImageRes.tempFilePaths[i];
							console.log("tempFilePaths", tempFilePaths);
							uni.uploadFile({
								url: '后端服务器上传接口',
								filePath: tempFilePaths,
								name: 'file',
								formData: {},
								success: uploadFileRes => {
									let img = JSON.parse(uploadFileRes.data).data;
									console.log("img", img);
									_this.list.push(img)
								}
							});
						}


					}
				});
			},
2.删除
touchstart(index) {
				let that = this;
				clearInterval(this.Loop); //再次清空定时器,防止重复注册定时器
				this.Loop = setTimeout(function() {
					uni.showModal({
						title: '删除',
						content: '请问要删除本图片吗?',
						success: async function(res) {
							if (res.confirm) {
								//   从数组中删除图片
								that.list.splice(index, 1);
								// 更新数组长度,使提示上传的图片再次显示
								// that.picPathListLength = that.list.length;
							} else if (res.cancel) {
								console.log("用户点击取消");
							}
						}
					});

				}.bind(this), 500);
			},
			touchend() {
				clearInterval(this.Loop);
			},
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值