🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
# uploadPhoto(上传图片模块封装) 相关代码如下: ``` /** * [uploadPhoto 上传图片模块封装] * @param {[string]} idName [img标签的id名称] */ function uploadPhoto(idName) { api.actionSheet({ cancelTitle: '取消', buttons: ['拍照', '打开相册'] }, function(ret, err) { if (ret.buttonIndex == 3) { return; } var sourceType = (ret.buttonIndex == 1) ? 'camera' : 'album'; api.getPicture({ sourceType: sourceType, destinationType: 'url', allowEdit: true, quality: 70, targetWidth: 100, targetHeight: 100 }, function(ret, err) { if (ret) { var img = ret.data; $api.attr($api.byId(idName), 'src', img); } else { alert(JSON.stringify(err)); } }); }); } ``` 相关示例: 相关图片: