国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 熱點 > 微信 > 正文

微信小程序實現(xiàn)圖片上傳

2024-07-22 01:18:19
字體:
來源:轉載
供稿:網友

本文實例為大家分享了Android九宮格圖片展示的具體代碼,供大家參考,具體內容如下/p>

圖片上傳服務器:

wxml

<view class="container"> <button bindtap='chooseImageTap'>上傳圖片</button></view>

wxss

Page({  /**  * 頁面的初始數(shù)據  */ data: {  imgs: [],//本地圖片地址數(shù)組  picPaths:[],//網絡路徑 },  /**  * 生命周期函數(shù)--監(jiān)聽頁面加載  */ onLoad: function (options) {   }, //添加上傳圖片 chooseImageTap: function () {  var that = this;  wx.showActionSheet({   itemList: ['從相冊中選擇', '拍照'],   itemColor: "#00000",   success: function (res) {    if (!res.cancel) {     if (res.tapIndex == 0) {      that.chooseWxImage('album')     } else if (res.tapIndex == 1) {      that.chooseWxImage('camera')     }    }   }  }) }, // 圖片本地路徑 chooseWxImage: function (type) {  var that = this;  var imgsPaths = that.data.imgs;  wx.chooseImage({   sizeType: ['original', 'compressed'],   sourceType: [type],   success: function (res) {    console.log(res.tempFilePaths[0]);    that.upImgs(res.tempFilePaths[0], 0) //調用上傳方法   }  })  }, //上傳服務器 upImgs: function (imgurl, index) {  var that = this;  wx.uploadFile({   url: 'https://xxxxxxxxxxxxxxxxxxxxxxxxxxxx',//   filePath: imgurl,   name: 'file',   header: {    'content-type': 'multipart/form-data'   },   formData: null,   success: function (res) {    console.log(res) //接口返回網絡路徑    var data = JSON.parse(res.data)     that.data.picPaths.push(data['msg'])     that.setData({      picPaths: that.data.picPaths     })     console.log(that.data.picPaths)   }  }) }, })

思路很簡單,多張上傳的話,在 upImgs 方法回調做判斷 index++ 繼續(xù)調用 upImgs方法即可

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持錯新站長站。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 阿合奇县| 勐海县| 扶沟县| 温宿县| 阜城县| 阳信县| 梅河口市| 印江| 望江县| 江北区| 乳源| 涞水县| 湾仔区| 西贡区| 芒康县| 林周县| 驻马店市| 延吉市| 台山市| 越西县| 施甸县| 禹城市| 东辽县| 五华县| 泾阳县| 齐齐哈尔市| 卫辉市| 河北区| 沙洋县| 湘阴县| 菏泽市| 滦平县| 房产| 古浪县| 会东县| 饶阳县| 梧州市| 榆社县| 沛县| 榕江县| 关岭|