takePhoto() {
uni.chooseImage({
count: 1,
sourceType: ['camera'],
success: (res) => {
// console.log(res);
// 图片信息:res.tempFilePaths
// 获取图片路径在页面上预览图片
this.srcs = res.tempFilePaths[0]
// 在这里可以对拍照的照片进行处理,例如上传至服务器或保存至本地console.log(tempFilePaths)
console.log('成功');
}
})
},
html代码
camera摄像头视口
点击调用摄像头
预览图片
<camera device-position="back" flash="off" @error="error" style="width: 100%; height: 300px;"></camera>
<button type="primary" @click="takePhoto">拍照</button>
<view>预览</view>
<image mode="widthFix" :src="srcs"></image>