UNIAPP云开发用uni-file-picker组件实现单图片上传

1. 在html部分

		<form @submit="formSubmit">
			<view>Name</view>
			<uni-easyinput  v-model="name" placeholder="" name="name"/>
			<view>price</view>
			<uni-easyinput v-model="price"  name="price"></uni-easyinput>
			<view>desc</view>
			<uni-file-picker @success="su" return-type="object" v-model="desc" name="desc" title="hello imge"  file-mediatype="image"></uni-file-picker>
			<button form-type="submit" size="default">提交</button>
		</form>

2.在脚本部分

	function formSubmit(e){
		console.log(e);
		   const {name,price}=e.detail.value
			const db = uniCloud.databaseForJQL();
			db.collection('sj-product')
			.add({name:name,price:parseInt(price),desc:desc.value.path+desc.value.extname})
			.then((res) => {
				console.log(res);
			})
			.catch((err) => {
				uni.showToast({
					title: '出错了,请联系管理员'
				});
			})
			
		}

需要注意,

1.在提交事件中并不到自动得到uni-file-picker组件的上传成功的返回值

2.组件中的return-type取值为array和Object, 默认为arrar,改为Object后只就能单文件上.

3.在数据库jql中,用得到的数组值或对象值(即上传文件的云储地址)来拼接add方法参数.

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值