1. 程式人生 > 實用技巧 >day08獲取圖片

day08獲取圖片

wxml:

<!--pages/publish/publish.wxml-->
<text>pages/publish/publish.wxml</text>
<view bindtap="uploadImage">請上傳圖片</view>
<view class="container">
<image wx:for="{{imageList}}" wx:key="key" src="{{item}}"></image>
</view>

js:

data: {
imageList:["/pages/static/flower.jpg","/pages/static/horse.jpg"]
},
uploadImage:function(){
var that=this;
wx.chooseImage({
count:,
sizeType:['original','compressed'],
sourceType:['album','camera'],
success:function(res){
//設定imagelist,頁面上圖片自動修改
that.setData({
imageList:res.tempFilePaths
});
//預設圖片+選擇的圖片
that.setData({
imageList:that.data.imageList.concat(res.tempFilePaths)
})
}
})
}, ===========================總結========================
事件:
1.bindtap 可以理解成點選事件
api:
1、navigateTo
wx.navigateTo({
url:'/pages/redirect/redirect?id='+nid
    })
2、openSetting
wx.openSetting({})
3、getUserInfo
wx.getUserInfo({
success:function(res){
console.log(res)
}
})
注意:結合button按鈕實現
4、chooseLocation
wx.chooseLocation({
success:function(res){
}
}),
5、chooseImage
wx.chooseImage({
count:9,
sizeType:['original','compressed'],
sourceType:['album','camera'],
success:function(res){}
})
資料繫結
for指令
注意:setData+that