Examples of uploading small program images: Uploading small program Images
1. Learn more about wx. chooseImage (OBJECT)
Ii. Code Programming
Create an uploadimg folder in the pages File
1. Compile the Page Structure: uploadimg. wxml
<View class = "container" style = "padding: 1rem; "> <button type =" primary "bindtap =" chooseimage "> image retrieval </button> <image src =" {tempFilePaths} "mode =" aspecFill "style =" width: 100%; height: interval RPX; margin: 1rem 0; "/> </view>
2. Set Data: uploadimg. js
// Obtain the application instance var app = getApp () Page ({data: {tempFilePaths: '',},/*** upload image */chooseimage: function () {var _ this = this; wx. chooseImage ({count: 1, // 9 by default // you can specify the source image or compressed image. Both have sizeType: ['original', 'compressed '] by default. // you can specify whether the source is an album or a camera. By default, both of them have sourceType: ['alipay', 'camera '], and // return the list of local file paths of the selected photo, tempFilePath can be used as the src attribute of the img label to display the image success: function (res) {_ this. setData ({tempFilePaths: res. tempFilePaths })}})}})
Thank you for reading this article. I hope it will help you. Thank you for your support for this site!