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

首頁 > 課堂 > 小程序 > 正文

微信小程序實現圖片上傳

2020-03-21 15:55:27
字體:
來源:轉載
供稿:網友

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

圖片上傳服務器:

wxml

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

wxss

Page({  /**  * 頁面的初始數據  */ data: {  imgs: [],//本地圖片地址數組  picPaths:[],//網絡路徑 },  /**  * 生命周期函數--監聽頁面加載  */ 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++ 繼續調用 upImgs方法即可

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 赣州市| 枣庄市| 庄浪县| 白沙| 松桃| 湘阴县| 海兴县| 阿鲁科尔沁旗| 定远县| 易门县| 姜堰市| 台州市| 嘉荫县| 徐汇区| 兴城市| 凤阳县| 长垣县| 右玉县| 桃园县| 揭阳市| 沭阳县| 阜阳市| 东山县| 随州市| 临沧市| 贵港市| 大渡口区| 化隆| 罗田县| 龙州县| 乌海市| 林甸县| 盐津县| 双城市| 磴口县| 大理市| 威信县| 河池市| 余江县| 甘南县| 泾阳县|