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")
			},
		}

你可能感兴趣的:(javasrcipt,uview,javascript,vue.js)