如图:
<view class="flex-sub flex" v-else-if="field.type=='image'||!field.type">
<view class="flex-sub">
<image v-if="form[field.name]" :src="form[field.name]" mode="aspectFill"
:lazy-load="true" />
<view class="placeholder-image"
:style="{ width: field.width + 'rpx', height: field.height + 'rpx' }">
<text>{{ field.placeholder || '点击上传图片' }}</text>
</view>
</view>
<view class="">
<view class="cu-btn sm bg-blue round" @click="selectImage(field)">
选择图片
</view>
</view>
</view>
selectImage(field) {
uni.chooseImage({
count: 1, // 默认选一张
sizeType: ['original', 'compressed'], // 可以指定原图或压缩图
sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机
success: (res) => {
const tempFilePaths = res.tempFilePaths[0];
// 将图片路径存入表单对象
this.$set(this.form, field.name, tempFilePaths);
},
fail: function(err) {
console.error('选择图片失败', err);
}
});
},
标签:uniapp,err,tempFilePaths,field,res,上传,图片
From: https://blog.csdn.net/Cwhat/article/details/137259342