Vue可以调用手机相机功能进行拍照。你可以使用 HTML5 的 <input>
元素的 type
属性设置为 "file",然后在移动设备上打开相机进行拍照。
<input type="file" accept="image/*" capture="camera" @change="handleFileChange" />
我们设置了 <input>
元素的 type
属性为 "file",accept
属性为 "image/*",这将限制选择文件类型为图片。然后通过 capture
属性指定了使用相机进行拍照。当用户拍照完成后,会触发 change
事件,我们可以在 handleFileChange
方法中获取到拍照的文件对象,然后进行进一步的处理。
handleFileChange(event) {
const file = event.target.files[0]
}