- 当前 Bug 的表现(可附上截图)
代码是这样写的:
selectImage(){
wx.showActionSheet({
itemList: ['拍照', '相册'],
success(res) {
console.log(res.tapIndex);
let sourcetype = ['camera','album'];
wx.chooseImage({
count: 1,
sizeType: ['original', 'compressed'],
sourceType: sourcetype[res.tapIndex],
success(response) {
// tempFilePath可以作为img标签的src属性显示图片
const tempFilePaths = response.tempFilePaths
console.log(tempFilePaths);
}
})
},
fail(res) {
console.log(res.errMsg)
}
})
},
在真机调试中不能唤起相机或者相册
- 预期表现
可以打开系统相册或者相机
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<title>选择图片</title>
<script type="text/javascript" src="${request.contextPath}/lib/jquery/jquery-3.1.1.min.js"></script>
<script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
<script>
wx.config({
debug: true,
appId: '${sign.appId}',
timestamp: '${sign.timestamp}',
nonceStr: '${sign.nonceStr}',
signature: '${sign.signature}',
jsApiList: ['checkJsApi','chooseImage','scanQRCode']
});
wx.ready(function() {
wx.checkJsApi({
jsApiList: ['chooseImage','scanQRCode']
});
var images = {
localId: [],
serverId: []
};
$('#submit_photo').on('click', function() {
alert("chooseImage start!"); //能弹出
wx.chooseImage({
success: function(res) {
alert("chooseImage success!"); //不能弹出
images.localId = res.localIds;
//var localId = res.localIds[0];
//$('#submit_photo').attr('src', localId.toString());
},
error: function(res) {
alert("chooseImage error!"); //不能弹出
},
fail: function(res) {
alert("chooseImage fail!"); //不能弹出
},
complete: function(res) {
alert("chooseImage complete!"); //不能弹出
}
});
});
$('#scanQr').on('click', function() {
alert("scanQr start!"); //能弹出
wx.scanQRCode({
success: function(res) {
alert("scanQr success!"); //能弹出
}
});
});
});
</script>
</head>
<body>
<img src="${request.contextPath}/static/images/noimage.png" style="height:300px; width:300px" id="submit_photo"/>
<input type="text" value="" id="photoId" />
<br>
<br>
<button id="scanQr" style="height:120px; width:300px">扫一扫</button>
</body>
</html>
有可能是你的真机的微信本身没有获取到使用系统的相机或储存空间的权限导致的。
权限问题吧
直接这样写不行吗? sourceType: ['camera','album'];
这样写我这边也可以调起相机相册啊
我想拉起菜单:相机和相册,然后根据来源做 应该没问题吧
嗯!!按道理他这样应该也没错,但是呢他定位错误在
chooseImage
没反应。。。。
要不你做个可以复现的代码片段吧,你贴出来的代码没问题的,或者就是楼上说的你手机没权限
我把菜单去掉了 直接用wx.chooseImage现在可以用就行了 谢谢大家~