Summary of common problems in WeChat development

Source: Internet
Author: User
This article describes the development of common problems, people do not understand the development of common problems or interested in developing common problems then we will take a look at this article, all right, let's get to the point.

Summary of common problems in development

1. Because the applet Wx.request () method is asynchronous, it cannot be loaded sequentially when the App.js performs Ajax, and each page loads app.js global data. Cases:

App.jsapp ({  ajax:function () {let]    = this;    Wx.request ({      URL: ' https://a.com/url.php ',      method: ' GET ',      success:function (e) {        that.data = 123;      }    })  };}) Content.jslet app = Getapp () Page ({  getdata:function () {;    App.ajax ();    Console.log (App.data); Undefined  }})


Workaround, use the Promise Async function:

App.jsapp ({  ajax:function () {let]    = this;    Let promise = new promise (function (resolve, reject) {      wx.request ({        URL: ' https://a.com/url.php ',        method: ' GET ',        success:function (e) {          that.data = 123;          Resolve ();})    }  ) Content.jslet app = Getapp () Page ({  getdata:function () {;    App.ajax (). Then (() =>{      console.log (app.data);//123    });}  )

2. The image can only get the original width height and cannot get the existing width height. However, the image tag encapsulates the Mode property and can be set on demand.

3. Each image tag has a transparent interval at the bottom, non-padding, non-margin. You may get a hole in the front of the picture when you make a mask layer.

4. Network requests must be deployed HTTPS

5. When configuring Tabbar, the Pagepath parameter in the list parameter needs to contain at least the first path in the App.json pages array, or it will cause tabbar not to appear.

6.tabBar jump with no parameters, workaround:

Search.jsvar app = Getapp (); Page ({  confirm:function (e) {    ///Gets data, added to global let    val = e.detail.value;    App.searchword = val;    This.jump ();  },  jump:function () {    //jump Tabbar    wx.switchtab ({      URL: '). /index/index ',    });  });  Index.jsvar app = Getapp (); Page ({  onshow:function (e) {    //Get Global data let    val = App.searchword;  }}); /pages that need to pass parameters are added to the app.js before jumping. Pages that need to accept parameters are added to app.js data before the OnShow method is accepted.

7. Applet Wx.request () method The URL requested must be the beginning of HTTPS

8.wx.request () When using the Post method request, you also need to add the Header,header[content-type] value to application/x-www-form-urlencoded. Cases:


Wx.request ({  URL: ' https://a.com/url.php ',  data: {message:123},  method: ' POST ',  header: {    ' Content-type ': ' application/x-www-form-urlencoded '  },  success:function (e) {    console.log (e)  }});


9. Applet cannot load HTML tags, and data rendering cannot render Wxml tags (<view></view>, etc.), you can use Wxparse.js to process related data.

10. Android cannot render the data requested by Wx.request ().

Detects if the returned data has a BOM header (3 characters blank). The Wx.request parsing of Android does not skip the BOM header, causing the data to return a string instead of an object or an array.

Cases:

The returned data is: (3 characters blank) {a:1, b:2}

The parsed data is: ' {a:1, B:2} ' (string), not {a:1, b:2} (object)

Template rendering will not work properly because it is not an object. Workaround, remove the BOM header before returning the data in the background. If the background does not go to the BOM header, can be removed at the front end, but wx.request if datatype default, will default to JSON and automatically resolve, resulting in the BOM header cannot be removed.

Solution:

Wx.request ({  Url:url,  method: ' GET ',  dataType: ' txt ',  success:function (e) {let    json = E.data.trim ();    Let arr = Json.parse (JSON);  }});

DataType changes to a format other than JSON, prevents the applet from parsing the JSON string automatically, then strips the returned data with the trim () method, and finally parses the JSON string.

11. Multi-line ellipsis (-webkit-line-clamp) is normal when debugging, and multi-line ellipsis is invalid when publishing.

Solution: If you do not want to re-audit, let the background truncation is good

12. One-time SetData length limit: 1048576

APPSERVICE:16 Invokewebviewmethod Data transmission length of 2432088 has exceeded the maximum length of 1048576

Easy to happen when using rich text, especially when the picture is Base64 and the pixels are very large.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.