亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Home WeChat Applet Mini Program Development WeChat applet-getUserInfo callback introduction

WeChat applet-getUserInfo callback introduction

Jun 22, 2018 pm 03:53 PM

This article mainly introduces the relevant information about the detailed explanation of the WeChat applet-getUserInfo callback example. I hope this article can help everyone understand and master this part of the content. Friends in need can refer to it

WeChat Mini Program-Detailed Example of GetUserInfo Callback

Foreword:

I won’t brag about how powerful the WeChat Mini Program is, after all. I wrote it to talk directly about the strange bugs I encountered while developing small programs.

getUserInfo is called multiple times:

Many developers should have used wx.getUserInfo, which is used to obtain basic user information. The premise is that user authorization is required. If the user If there was no authorization before, a prompt box will pop up as follows:

After clicking Allow, we can get the user information and perform a series of subsequent operations. This all looks so good, but during a certain run, after clicking Allow Authorization, the program did not execute as we expected. Finally, I found that the wx.getUserInfo method was also called in other places, and only one of the callbacks for successful authorization was executed. Assume the following code:

Conclusion:

1. If the user is authorized: A B C will be printed.

2. The user is not authorized: After clicking Allow, one of the three numbers A, B, and C will be printed randomly.

Of course it is best not to call the wx.getUserInfo method in multiple places at the same time, otherwise you will have a headache when encountering this problem. My view on this issue is that calling the getUserInfo method multiple times will only generate an instance of the pop-up window, so when you click Allow, it is normal to only execute the callback once, but it is strange to execute one of the methods randomly.

Solution:

1. Do not call the wx.getUserInfo method at the same time. There are very few situations where it is necessary to call it at the same time.

2. Encapsulate a getUserInfo method, store the incoming callback method into an array, and clear the array after traversing the calls in the authorization success/failure callback.

The following is the test environment:

WeChat developer tool version: v1.01.170925

Basic library version: 1.3.0

The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

How to use switchTab in WeChat applet development

How to use the UI framework in WeChat applet development

Usage of container view in WeChat applet development

The above is the detailed content of WeChat applet-getUserInfo callback introduction. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)