随手拍
<view class="cardContent">
<!-- 拍照功能 -->
<view>
<image :src="imageList.length==0 ? imgeUrl:imageList " @click="onGetImgClick()">
</view>
</view>
、
onGetImgClick: function() {
uni.chooseImage({
sizeType: ['compressed'], //original 原图,compressed 压缩图,默认二者都有
sourceType: ['album', 'camera'], //album 从相册选图,camera 使用相机,默认二者都有。如需直接开相机或直接选相册,请只使用一个选项
success: res => {
this.imageList = res.tempFilePaths[0]
console.log('res',res)
console.log(this)
uni.uploadFile({
url: ``, //接口
filePath: res.tempFilePaths[0],
// formData: {
// name: 'token',
// token: window.uni.getStorageSync("accessToken")
// },
name: 'multipartFile',
header:{
token:this.accessToken,
},
file:res.tempFiles[0],
success: res => {
this.objList = JSON.parse(res.data)
if (this.objList.code == 200) {
this.newtime = this.objList.time
this.resData = this.objList.data
console.log(this.objList, this.newtime, this.resData,
'6666')
console.log(this)
}
}
})
}
})
},
#功能截图
这个代码只能拍一张之后进行替换,如果需要拍多张改一下file就可以
#注意事项
当时做这个功能的时候遇到一个问题。 filePath可以打印出来 但是 this.objList, this.newtime, this.resData,打印不出来,后来发现是this指向的问题。 这也是为什么要用箭头函数。