微信小程式 圖片上傳執行個體詳解,小程式圖片上傳

來源:互聯網
上載者:User

小程式 圖片上傳執行個體詳解,小程式圖片上傳

一.瞭解wx.chooseImage(OBJECT)


二.代碼編程

在pages檔案裡面建立uploadimg檔案夾

1.編寫頁面結構:uploadimg.wxml

<view class="container" style="padding:1rem;">   <button type="primary"bindtap="chooseimage">擷取圖片</button>    <image src="{{tempFilePaths }}" mode="aspecFill" style="width: 100%; height: 450rpx;margin:1rem 0;"/>  </view>


2.設定資料:uploadimg.js

//擷取應用執行個體  var app = getApp()  Page({   data: {      tempFilePaths: '',    },   /**     * 上傳圖片    */   chooseimage: function () {      var _this = this;      wx.chooseImage({        count: 1, // 預設9        // 可以指定是原圖還是壓縮圖,預設二者都有        sizeType: ['original', 'compressed'],        // 可以指定來源是相簿還是相機,預設二者都有       sourceType: ['album', 'camera'],       // 返回選定照片的本地檔案路徑列表,tempFilePath可以作為img標籤的src屬性顯示圖片         success: function (res) {               _this.setData({           tempFilePaths:res.tempFilePaths          })        }      })    }  }) 


感謝閱讀,希望能協助到大家,謝謝大家對本站的支援!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.