個人信息——頭像更換(拍照或相冊上傳)~ 微信小程序


微信小程序中 在用戶信息中關於用戶頭像更換(拍照或相冊上傳)功能實現。

圖像點擊觸發事件:

<image src='{{personImage}}' bindtap='changeAvatar' ></image>
Page({
 data:{},  changeAvatar:function(){ const _this = this; wx.chooseImage({ count: 1, sizeType: ['original', 'compressed'], sourceType: ['album', 'camera'], success(res) { // tempFilePath可以作為img標簽的src屬性顯示圖片 const tempFilePath = res.tempFilePaths[0]; _this.setData({ personImage: tempFilePath }) wx.uploadFile({ url: config.UPLOADFILE, //圖片上傳至開發服務器接口 filePath: tempFilePath, name: 'file', formData: {}, success(res) { const data = res.data; console.log(data); } }) } }) } })

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM