复制代码<template>
<view>
<camera
mode="normal"
id="camera"
flash="off"
frame-size="medium"
device-position="back"
@ready="onCameraReady"
style="width: 100%; height: 300px"
/>
</view>
</template>
<script>
export default {
data() {
return {
cameraContext: '',
}
},
methods: {
onCameraReady (e) {
this.cameraContext = uni.createCameraContext();
this.cameraContext.takePhoto ({
quality: 'high',
success (res) {
console.log (res);
},
fail (err) {
console.log (err);
},
});
}
},
};
</script>
<style>
</style>

- 发布:2023-11-15 16:34
- 更新:2023-11-15 16:34
- 阅读:278
产品分类: uniapp/小程序/阿里
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: win11
第三方开发者工具版本号: 2.9.0
基础库版本号: 2.7.12
项目创建方式: CLI
CLI版本号: 2.9.6
示例代码:
操作步骤:
执行以上代码,跑真机
执行以上代码,跑真机
预期结果:
success打印具体内容
success打印具体内容
实际结果:
success、fail、complete都没打印
success、fail、complete都没打印
bug描述:
1、使用uni-app框架调用uni.cameraContext.takePhoto,报错且该方法无响应,success、fail、complete都没打印
Property or method "toJSON" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property.
2、在method加上toJSON(){},无报错,但takephoto无响应
但使用支付宝原生框架调用my.cameraContext.takePhoto,正常无报错有响应

