我正在尝试学习 vue-native 并创建一个练习应用程序来使用相机和捕捉图像。在文档中,他们使用一些ref
将相机分配给它,但我不知道在 vue-native 中传递 ref 的确切方法。我做了很少的功课,在 git 上发现了这个问题,但它也没有帮助。
参考: https ://github.com/GeekyAnts/vue-native-core/issues/88
文档(vue-native): https ://vue-native.io/docs/device-apis.html#Camera
文档(世博相机): https ://docs.expo.io/versions/latest/sdk/camera/#takepictureasync
代码片段是:
<template>
<view class="container">
<camera
class="camera"
:type=type
ref="camera"
>
<view class="camera-view-1">
<view class="camera-view-2">
<view class="camera-view-3">
<touchable-opacity
class="camera-touchable-opacity"
:on-press="_takePicture"
>
<text style="color: #FF0000">Capture</text>
</touchable-opacity>
</view>
</view>
</view>
</camera>
<view>
<touchable-opacity
:on-press="_changeCamera">
<text class="change-cam"> Change Camera </text>
</touchable-opacity>
<button title="Go to home screen" @press="goToHomeScreen"></button>
</view>
</view>
</template>
<script>
import * as Permissions from 'expo-permissions';
import { Camera } from 'expo-camera';
export default {
data: function() {
return {
hasCameraPermission: false,
type: Camera.Constants.Type.back,
img: '',
};
},
props: {
navigation: { type: Object }
},
methods: {
goToHomeScreen() {
this.navigation.navigate("Home");
},
_changeCamera: function() {
this.type = (this.type === Camera.Constants.Type.back ? Camera.Constants.Type.front : Camera.Constants.Type.back);
},
_takePicture: async function() {
if(!camera) return;
const photo = await camera.takePictureAsync();
}
},
mounted: function() {
Permissions.askAsync(Permissions.CAMERA)
.then(status => {
hasCameraPermission = status.status == "granted" ? true : false;
}).catch((err)=>{
console.log(err);
});
},
components: { Camera },
};
</script>
<style>
.container, .camera {
flex: 1;
}
.change-cam {
color: #FF0000;
text-align: center;
}
</style>
当我单击捕获按钮时,我收到一个camera
未定义的错误。我认为我没有ref
正确使用。有人可以建议使用它的正确方法vue-native
吗?谢谢