Summary of common problems in WeChat development
This article talks about common problems in WeChat development. If you don’t know about common problems in WeChat development or are interested in common problems in WeChat development, then let’s take a look at this article together. Okay, without further ado, enter Let’s get to the point
Summary of common problems in WeChat development
1. Since the wx.request() method of the mini program is asynchronous, after app.js executes ajax, each When loading the global data of app.js in pages, it cannot be loaded in order. Example:
//app.js App({ ajax:function(){ let that = this; wx.request({ url: 'https://a.com/url.php', method: 'GET', success: function(e){ that.data = 123; } }) }; }) //content.js let app = getApp() Page({ getData: function(){; app.ajax(); console.log(app.data); //undefined } })
Solution, use Promise asynchronous function:
//app.js App({ ajax:function(){ let that = 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.js let app = getApp() Page({ getData: function(){; app.ajax().then(()=>{ console.log(app.data); //123 }); } })
2. The picture can only obtain the original width and height, but cannot obtain the existing width and height. However, the image tag encapsulates the mode attribute, which can be set according to needs.
3. There is a transparent space at the bottom of each image tag, not padding, not margin. You may get stuck when making a mask layer in front of the image.
4. Network requests must deploy https
5. When configuring tabBar, the pagePath parameter in the list parameter needs to contain at least the first path in the pages array in app.json, otherwise it will cause tabBar is not displayed.
6.TabBar cannot take parameters when jumping. Solution:
//search.js var app = getApp(); Page({ confirm: function(e){ //获取数据,添加到全局 let val = e.detail.value; app.searchWord = val; this.jump(); }, jump: function(){ //跳转tabBar wx.switchTab({ url: '../index/index', }); }, }); //index.js var app = getApp(); Page({ onShow: function(e){ //获取全局数据 let val = app.searchWord; } }); //需要传递参数的页面在跳转前将数据添加到app.js里。需要接受参数的页面在onShow方法接受之前添加到app.js的数据。
7. The url requested by the wx.request() method of the mini program must start with https
8 When .wx.request() uses the post method to request, you also need to add a header. The header[content-type] value is application/x-www-form-urlencoded. Example:
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. The applet cannot load the html tag, and data rendering cannot render the wxml tag (
10. Android cannot render the data requested by wx.request().
Check whether the returned data has a BOM header (3 characters of blank space). Android's wx.request parsing does not skip the BOM header, causing the data to be returned as a string instead of an object or array.
Example:
The returned data is: (3 characters of blank){a:1, b:2}
The parsed data is: '{a: 1, b:2}' (string), not {a:1, b:2} (object)
Because it is not an object, template rendering and the like will not work properly. The solution is to remove the BOM header before returning data in the background. If the BOM header is not removed in the background, it can be removed on the front end. However, if the dataType of wx.request is default, it will default to json and be automatically parsed, making it impossible to remove the BOM header.
Solution:
wx.request({ url: url, method: 'GET', dataType: 'txt', success: function(e){ let json = e.data.trim(); let arr = JSON.parse(json); } });
Change the dataType to a format other than json to prevent the applet from automatically parsing the json string, and then use trim( ) method to remove the blanks and finally parse the json string.
11. Multi-line omission (-webkit-line-clamp) is normal during debugging, but invalid when publishing.
Solution: If you don’t want to re-audit, just let the background truncate
12. There is a limit to the length of a single setData: 1048576
appservice:16 invokeWebviewMethod data transmission The length is 2432088 and has exceeded the maximum length of 1048576
It is easy to happen when using rich text, especially when the image is base64 and the pixels are very large
The above is all of this article If you don’t know much about the content, you can easily master it by implementing more of both sides!
Related recommendations:
WeChat development Token verification failure solution
WeChat development obtains JSAPI Example sharing of TICKET
The above is the detailed content of Summary of common problems in WeChat development. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Summary of the system() function under Linux In the Linux system, the system() function is a very commonly used function, which can be used to execute command line commands. This article will introduce the system() function in detail and provide some specific code examples. 1. Basic usage of the system() function. The declaration of the system() function is as follows: intsystem(constchar*command); where the command parameter is a character.

Solve the "error:redefinitionofclass'ClassName'" problem in C++ code. In C++ programming, we often encounter various compilation errors. One of the common errors is "error:redefinitionofclass 'ClassName'" (redefinition error of class 'ClassName'). This error usually occurs when the same class is defined multiple times. This article will

The clustering effect evaluation problem in the clustering algorithm requires specific code examples. Clustering is an unsupervised learning method that groups similar samples into one category by clustering data. In clustering algorithms, how to evaluate the effect of clustering is an important issue. This article will introduce several commonly used clustering effect evaluation indicators and give corresponding code examples. 1. Clustering effect evaluation index Silhouette Coefficient Silhouette coefficient evaluates the clustering effect by calculating the closeness of the sample and the degree of separation from other clusters.

Known for its powerful performance and versatile features, the iPhone is not immune to the occasional hiccup or technical difficulty, a common trait among complex electronic devices. Experiencing iPhone problems can be frustrating, but usually no alarm is needed. In this comprehensive guide, we aim to demystify some of the most commonly encountered challenges associated with iPhone usage. Our step-by-step approach is designed to help you resolve these common issues, providing practical solutions and troubleshooting tips to get your equipment back in peak working order. Whether you're facing a glitch or a more complex problem, this article can help you resolve them effectively. General Troubleshooting Tips Before delving into specific troubleshooting steps, here are some helpful

To solve the problem that jQuery.val() cannot be used, specific code examples are required. For front-end developers, using jQuery is one of the common operations. Among them, using the .val() method to get or set the value of a form element is a very common operation. However, in some specific cases, the problem of not being able to use the .val() method may arise. This article will introduce some common situations and solutions, and provide specific code examples. Problem Description When using jQuery to develop front-end pages, sometimes you will encounter

The label acquisition problem in weakly supervised learning requires specific code examples. Introduction: Weakly supervised learning is a machine learning method that uses weak labels for training. Different from traditional supervised learning, weakly supervised learning only needs to use fewer labels to train the model, rather than each sample needs to have an accurate label. However, in weakly supervised learning, how to accurately obtain useful information from weak labels is a key issue. This article will introduce the label acquisition problem in weakly supervised learning and give specific code examples. Introduction to the label acquisition problem in weakly supervised learning:

The generalization ability of machine learning models requires specific code examples. With the development and application of machine learning becoming more and more widespread, people are paying more and more attention to the generalization ability of machine learning models. Generalization ability refers to the prediction ability of a machine learning model on unlabeled data, and can also be understood as the adaptability of the model in the real world. A good machine learning model should have high generalization ability and be able to make accurate predictions on new data. However, in practical applications, we often encounter models that perform well on the training set, but fail on the test set or real

What are the questions involved in the Yulong 8 Wine Master exam? What is the corresponding answer? How to pass the exam quickly? There are many questions that need to be answered in the Master of Wine Examination activities, and we can refer to the answers to solve them. These questions all involve knowledge of wine. If you need a reference, let’s take a look at the detailed analysis of the answers to the Yakuza 8 Wine Master exam questions! Detailed explanation of answers to questions in the Rulong 8 Wine Master exam 1. Questions about "wine". This is a distilled liquor produced by a distillery established by the royal family. It is brewed from the sugar of sugarcane grown in large quantities in Hawaii. What is the name of this wine? Answer: Rum 2. Question about "wine". The picture shows a drink made from dry ginseng and dry vermouth. It is characterized by the addition of olives and is known as "cockney"
