WeChat小程序交流(QQ群:769977169)
效果图(注意:真机才能显示)
代码示例:
xxx.wxml
<button bindtap='imageSelect'>图片选择</button>
<view class='imageStyle'>
<block wx:for="{{imageUrls}}">
<image src="{{item}}" mode="widthFix" style="width:100%;background-color:#eeeeee;margin-top:10px"></image>
</block>
</view>
xxx.wxjs
Page({
/**
* 页面的初始数据
*/
data: {
imageUrls:null
},
imageSelect: function(even) {
var thisBlock = this;
wx.showActionSheet({
itemList: ['相册', '拍照'],
success: function(res) {
var type = null;
if (0 == res.tapIndex) {
type = 'album'
} else if (1 == res.tapIndex) {
type = 'camera'
}
if (type.length > 0){
wx.chooseImage({
count: 5,
sizeType: "original",
sourceType: type,
success: function (res) {
console.log(res.tempFilePaths)
thisBlock.setData({
imageUrls: res.tempFilePaths
})
},
})
}
}
})
}
}
xxx.wxss
.imageStyle{
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
margin: 10px;
}