网友真实露脸自拍10p,成人国产精品秘?久久久按摩,国产精品久久久久久无码不卡,成人免费区一区二区三区

小程序模板網

獨立開發微信小程序——“桌游聚樂會”項目實踐上線

發布時間:2017-12-15 09:03 所屬欄目:小程序開發教程

微信小程序上傳一或多張圖片

 
 
 

一.要點

1.選取圖片

 

						
  1. wx.chooseImage({
  2. sizeType: [], // original 原圖,compressed 壓縮圖,默認二者都有
  3. sourceType: [], // album 從相冊選圖,camera 使用相機,默認二者都有
  4. success: function (res) {
  5. console.log(res);
  6. var array = res.tempFilePaths, //圖片的本地文件路徑列表
  7. }
  8. })

2.上傳圖片

 

						
  1. wx.uploadFile({
  2. url: '', //開發者服務器的 url
  3. filePath: '', // 要上傳文件資源的路徑 String類型!!!
  4. name: 'uploadFile', // 文件對應的 key ,(后臺接口規定的關于圖片的請求參數)
  5. header: {
  6. 'content-type': 'multipart/form-data'
  7. }, // 設置請求的 header
  8. formData: { }, // HTTP 請求中其他額外的參數
  9. success: function (res) {
  10. },
  11. fail: function (res) {
  12. }
  13. })

二.代碼示例

 

						
  1. // 點擊上傳圖片
  2. upShopLogo: function () {
  3. var that = this;
  4. wx.showActionSheet({
  5. itemList: ['從相冊中選擇', '拍照'],
  6. itemColor: "#f7982a",
  7. success: function (res) {
  8. if (!res.cancel) {
  9. if (res.tapIndex == 0) {
  10. that.chooseWxImageShop('album')
  11. } else if (res.tapIndex == 1) {
  12. that.chooseWxImageShop('camera')
  13. }
  14. }
  15. }
  16. })
  17. },
  18. chooseWxImageShop: function (type) {
  19. var that = this;
  20. wx.chooseImage({
  21. sizeType: ['original', 'compressed'],
  22. sourceType: [type],
  23. success: function (res) {
  24.  
  25. /*上傳單張
  26. that.data.orderDetail.shopImage = res.tempFilePaths[0],
  27. that.upload_file(API_URL + 'shop/shopIcon', res.tempFilePaths[0])
  28. */
  29.  
  30. /*上傳多張(遍歷數組,一次傳一張)
  31. for (var index in res.tempFilePaths) {
  32. that.upload_file(API_URL + 'shop/shopImage', res.tempFilePaths[index])
  33. }
  34. */
  35. }
  36. })
  37. },
  38. upload_file: function (url, filePath) {
  39. var that = this;
  40. wx.uploadFile({
  41. url: url,
  42. filePath: filePath,
  43. name: 'uploadFile',
  44. header: {
  45. 'content-type': 'multipart/form-data'
  46. }, // 設置請求的 header
  47. formData: { 'shopId': wx.getStorageSync('shopId') }, // HTTP 請求中其他額外的 form data
  48. success: function (res) {
  49. wx.showToast({
  50. title: "圖片修改成功",
  51. icon: 'success',
  52. duration: 700
  53. })
  54. },
  55. fail: function (res) {
  56. }
  57. })
  58. },


易優小程序(企業版)+靈活api+前后代碼開源 碼云倉庫:starfork
本文地址:http://www.xiuhaier.com/wxmini/doc/course/18173.html 復制鏈接 如需定制請聯系易優客服咨詢:800182392 點擊咨詢
QQ在線咨詢
AI智能客服 ×