In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "how to realize the photo album selection and photo function in WeChat Mini Programs". The content in the article is simple and clear, and it is easy to learn and understand. let's go deep into the editor's train of thought. Let's study and learn how to realize the photo album selection and photo function in WeChat Mini Programs.
Foreword:
There are two ways to get pictures in Mini Program. The first is to directly open your own style inside Wechat. The first frame is a camera photo, followed by a picture. The second is a pop-up box that prompts the user whether to take a picture or choose from a photo album. Let's take a look at it one by one.
The wx.chooseImage (OBJECT) function is used to select an album. The specific parameters are as follows:
Take a look directly at the code that opens the camera album:
Page ({data: {tempFilePaths:'}, onLoad: function () {}, chooseimage: function () {var that = this) Wx.chooseImage ({count: 1, / / default 9 sizeType: ['original',' compressed'], / / you can specify the original image or compressed image. By default, both have sourceType: ['album',' camera'], / / you can specify whether the source is a photo album or a camera, and by default both have success: function (res) {/ / return the local file path list of the selected photo TempFilePath can be used as the src attribute of the img tag to display that.setData ({tempFilePaths: res.tempFilePaths})})},})
The first effect of the method is as follows:
Personally, I think the second user experience is better, and the effect is as follows:
Click to get the pop-up box prompt, the code is as follows:
Page ({data: {tempFilePaths:'}, onLoad: function () {}, chooseimage: function () {var that = this) Wx.showActionSheet ({itemList: ['Select from album,' photo'], itemColor: "# CED63A", success: function (res) {if (! res.cancel) {if (res.tapIndex = = 0) {that.chooseWxImage ('album')} else if (res.tapIndex = = 1) {that.chooseWxImage (' camera')} ChooseWxImage: function (type) {var that = this Wx.chooseImage ({sizeType: ['original',' compressed'], sourceType: [type], success: function (res) {console.log (res); that.setData ({tempFilePaths: res.tempFilePaths [0],})
The temporary path of the file can be used normally during the startup of Mini Program. For persistent preservation, you need to call wx.saveFile actively and access it only when Mini Program is started next time.
Layout file:
Thank you for reading the pictures. The above is the content of "how to realize the album selection and photo function in WeChat Mini Programs". After the study of this article, I believe you have a deeper understanding of how to realize the album selection and photo function in WeChat Mini Programs, and the specific use still needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.