今天做了一個本地圖片上傳的功能,可以選擇單張圖片或者多張圖片,日常整理一下。
上代碼了
wxml:
<button type="primary" bindtap='image'>選擇圖片</button>
<view wx:for='{{imgArray}}'>
<image src='{{item}}'></image>
</view>
js:
data: {
imgArray:[]
},
image:function(e){
var _this = this;
wx.chooseImage({
count: 9, // 默認9
sizeType: ['original', 'compressed'], // 可以指定是原圖還是壓縮圖,默認二者都有
sourceType: ['album', 'camera'], // 可以指定來源是相冊還是相機,默認二者都有
success: function (res) {
console.log(res);
// 返回選定照片的本地文件路徑列表,tempFilePath可以作爲img標籤的src屬性顯示圖片
_this.setData({
imgArray:res.tempFilePaths
})
}
})
},
想要獲得更多資料的 請微信搜索公衆號 【熱血科技】,關注一下即可。