使用以下代码
const getCamera = () => {
navigator.mediaDevices
.getUserMedia({
audio: true,
video: { facingMode: { exact: "environment" } },
})
.then((stream) => {
// 摄像头开启成功
console.log(videoRef);
videoRef.value.srcObject = stream;
videoRef.value.play();
})
.catch((err) => {
console.log(err);
});
}
只需要将user改为environment
ヾ( ̄▽ ̄)Bye~Bye~