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:9, 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