This article mainly introduces the relevant information on the detailed explanation of the WeChat applet to obtain album photos. Friends who need it can refer to
WeChat applet to obtain album photos
Today I encountered the user avatar setting function of the WeChat applet and took notes.
First upload the gif:
Then 코드 추가:
작은 데모, 코드는 매우 간단합니다.
1.index.wxml
<!--index.wxml--> <button style="margin:30rpx;" bindtap="chooseimage">获取图片</button> <image src="{{tempFilePaths }}" mode="aspecFill" style="width: 100%; height: 450rpx"/>
2.index.js
//index.js //获取应用实例 var app = getApp() Page({ data: { tempFilePaths: '' }, onLoad: function () { }, chooseimage: function () { var _this = this; wx.chooseImage({ count: 1, // 默认9 sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有 sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有 success: function (res) { // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片 _this.setData({ tempFilePaths:res.tempFilePaths }) } }) } })
API 설명:
Note here: What is returned is the local path of the image. If you need to upload the image to the server, you need to use another API.
Sample code:
wx.chooseImage({ success: function(res) { var tempFilePaths = res.tempFilePaths wx.uploadFile({ url: 'http://example.weixin.qq.com/upload', //仅为示例,非真实的接口地址 filePath: tempFilePaths[0], name: 'file', formData:{ 'user': 'test' }, success: function(res){ var data = res.data //do something } }) } })
Thank you for reading, I hope it can help everyone, thank you everyone for supporting this site!
위 내용은 WeChat 애플릿을 통해 앨범 사진을 얻는 예에 대한 자세한 설명의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!