小程序上传图片

changeName: function(e) {
var that = this;
wx.chooseImage({
success: function(res) {
var userInfo = app.globalData.userInfo;
var tempFilePaths = res.tempFilePaths
wx.uploadFile({
url: app.globalData.siteUrl + "/Api.php?g=Api&c=Public&a=Upload", //仅为示例,非真实的接口地址
filePath: tempFilePaths[0],
name: 'imgFile',
formData: {
'uid': userInfo.uid
},
dataType: 'json',
success: function(res) {

 

that.setData({
logoImage: JSON.parse(res.data),
logo: true,
})
//do something
}
})
}
})

 

},
 
<view class='item upload-imgbox'>
 
<view class='uplonding flex' bindtap="changeName">
<image wx:if="{{logo==true}}" src='{{logoImage.url}}' style='width:50%;height:50%;'></image>
<view wx:if="{{logo==false}}" class='add-icon'></view>
<text wx:if="{{logo==false}}">上传公司LOGO图片</text>
</view>
</view>
 
posted @ 2018-10-10 14:40  为了自己  阅读(91)  评论(0编辑  收藏  举报