第一种格调:
wxml文件代码
<view class="address" hover-class="none" hover-stop-propagation="false"
bind:tap="chooseWxImage">
识别身份证
</view>
js文件代码:
此种看官方文档即可,就不展示图片了
chooseWxImage: function(type) {
var that = this;
wx.chooseImage({
sizeType: ['original', 'compressed'],
sourceType: ['album', 'camera'],
success: function(res) {
console.log(res);
that.setData({
img: res.tempFilePaths[0],
})
}
})
},
第二种格调:从下方弹出选项,先看效果图
wxml文件代码
<view class="address" hover-class="none" hover-stop-propagation="false" bindtap="chooseimage">
识别身份证
</view>
js文件代码
chooseimage: function() {
var that = this;
wx.showActionSheet({
itemList: ['从相册中选择', '拍照'],
itemColor: "#a3a2a2",
success: function(res) {
if (!res.cancel) {
if (res.tapIndex == 0) {
that.chooseWxImage('album')
} else if (res.tapIndex == 1) {
that.chooseWxImage('camera')
}
}
}
})
},
chooseWxImage: function(type) {
var that = this;
wx.chooseImage({
sizeType: ['original', 'compressed'],
sourceType: [type],
success: function(res) {
console.log(res);
that.setData({
// tempFilePath可以作为img标签的src属性显示图片
img: res.tempFilePaths[0],
})
}
})
},