1、cordova项目添加相机插件
cordova plugin add cordova-plugin-camera
检查已安装的cordova插件
cordova plugin ls
2、在static目录下,创建cordovaplugin.js文件,编写封装调用相机的接口
function cameraGetPicture() {
navigator.camera.getPicture(onSuccess, onFail, { quality: 50,
destinationType: Camera.DestinationType.DATA_URL,
sourceType: Camera.PictureSourceType.PHOTOLIBRARY
});
function onSuccess(imageURL) {
var image = document.getElementById('myImage');
image.src = imageURL;
}
function onFail(message) {
alert('Failed because: ' + message);
}
}
export{
cameraGetPicture
}
3、vue文件中进行调用
import { cameraGetPicture } from '../../static/cordovaplugin.js'
4、解决ios调用相机闪退问题
platform->ios->项目名->项目名- Info.plist里添加
<key>NSCameraUsageDescription</key>
<string>cameraDesciption</string>
文章参考:
1、https://blog.csdn.net/u011042316/article/details/83828371
2、https://www.w3cschool.cn/cordova/cordova_camera.html
3、https://blog.csdn.net/weixin_34265814/article/details/88826525