一.了解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 }) } }) } }) 
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
新聞熱點
疑難解答