使用macOS系统开发小程序,使用camera组件,开发者工具总是闪退,开通权限也不行
macOS:11.6
开发者工具:1.05.2201242
<template>
<view>
<view class="" v-if="isAuth">
<camera device-position="back" flash="auto" @error="error" style="width: 100%; height: 500upx;">
<cover-image src="../../static/scan-frame/scan-img.png" class="scan-img"></cover-image>
</camera>
</view>
<view class="scan-text">请将XXX放置白色框内</view>
<button type="primary" @click="takePhoto">拍照</button>
<image mode="widthFix" class="photos-box" :src="src"></image>
</view>
</template>
<script>
export default {
data() {
return {
src: '',
isAuth: false
};
},
onLoad() {
let _ = this;
wx.getSetting({
success(res) {
if (!res.authSetting['scope.camera']) {
wx.authorize({
scope: 'scope.camera',
success() {
_.isAuth = true;
}
});
}
}
});
},
methods: {
takePhoto() {
const ctx = uni.createCameraContext();
ctx.takePhoto({
quality: 'high',
success: res => {
this.src = res.tempImagePath;
/* 返回调用页面并把图片URL传递过去 */
/* let pages = getCurrentPages();
let prevPage = pages[pages.length - 2];
prevPage.setData({
"image": res.tempImagePath,
})
uni.navigateBack(); */
/* 调用页面获取图片URL方法 */
/* let pages = getCurrentPages();
let currPage = pages[pages.length-1];
if(typeof(currPage.data.image) != undefined && currPage.data.image != null){
console.log('获取图片:', currPage.data.image)
} */
}
});
},
error(e) {
console.log(e.detail);
}
}
};
</script>
<style>
.scan-img {
opacity: 0.4;
width: 100%;
height: 500upx;
}
.scan-text {
font-size: 20px;
text-align: center;
line-height: 60upx;
}
</style>
直接使用会有问题,不过可以巧妙的避过。
方法就是不要在开发者工具中使用,发布到手机上调试就可以