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方法参数.