Pitfalls encountered in the development of WeChat applets

Table of contents

1. clearInterval does not work

2. Set background: linear-gradient(180deg, #FCF8F5 0%, #FCF8F5 99.9%, transparent 100%); to solve the problem of black lines at the bottom of the element. But it doesn't work in ios.

3. wx.createAnimation, the set animation can only be executed once

4. The swiper is incompletely displayed on the Apple mobile phone (just open it), and this situation will also occur on the Android mobile phone (after repeated operations), as shown in the figure

5. The WeChat applet jumps and reports an error errMsg: “navigateTo:fail webview count limit exceed” (appears when the page is repeatedly operated)

6. Time calculation incompatibility between ios and Android

7. The mobile phone cannot obtain the local openid, which is mainly manifested in Apple mobile phones

8. The pit brought by onUnload


1. clearInterval does not work

Cause: Duplicate timer created

Solution: clear the timer before creating it

2. Set background: linear-gradient(180deg, #FCF8F5 0%, #FCF8F5 99.9%, transparent 100%); to solve the problem of black lines at the bottom of the element. But it doesn't work in ios.

Reason: ios is not compatible

Solution: background: linear-gradient(180deg, #FCF8F5 0%, #FCF8F5 99.9%, rgba(255,255,255,0) 100%);

3. wx.createAnimation, the set animation can only be executed once

Reason: The animation only executes the animation with difference

Solution: After executing an animation, return to the initial state in a few seconds

let animation = wx.createAnimation({
    duration: 2000,
    timingFunction: 'ease',
    delay: 0,
    transformOrigin: 'center center 0',
})
animation.opacity(0.5).rotate(360).step({
    duration: 3000
})
setTimeout(() => {
    animation.rotate(0).opacity(1).step({
       duration: 10
    })
}, 2000);

4. The swiper is incompletely displayed on the Apple mobile phone (just open it), and this situation will also occur on the Android mobile phone (after repeated operations), as shown in the figure

Reason: swiper and swiper-item add inline style

Solution: Remove the inline style

5. The WeChat applet jumps and reports an error errMsg: “navigateTo:fail webview count limit exceed” (appears when the page is repeatedly operated)

Reason: The wx.navigateTo and < navigator > components realize page jumping, which can only be up to five layers. When the page path is greater than five layers and exceeds the limit, an error will be reported.

 Solution: use wx.redirectTo

6. Time calculation incompatibility between ios and Android

Reason: iOS only supports the date format of 2020/01/01, not the format of 2020-01-01

Solution: Determine the mobile phone system, if it is ios, convert the time to the format of 2020/01/01

let platform;
wx.getSystemInfo({
   success: function (res) {
      platform = res.platform
   }
});
this.platform = platform

let inDate = 2023-06-06
if (this.platform == 'ios') {
    inDate = inDate.replace(/-/g, '/')
}

7. The mobile phone cannot obtain the local openid, which is mainly manifested in Apple mobile phones

Reason: Guess it may be caused by asynchronous

Solution: first judge whether there is an openid locally, if not, get it once after 200s

 

8. The pit brought by onUnload

Description: Set jump to page B (wx.reLaunch({ url: b })) in onUnload of page A, after page A exits (this exit must trigger the page jump event set in onUnload), scan the code Enter page A, find that page A is flashing, and enter page B directly. (Need to execute multiple times)

Possible reason: The official did not answer, but I feel that this blog is more reasonable, and it can explain the summary of the problems encountered by using the onUnload event in WeChat applets_Tong Yan Different Blog-CSDN Blog

It roughly means that after entering page A, the applet will have a cache. When you leave and enter, the cache will be cleared first, and the onUnload method will be called to jump directly to page B.

Solution: Like the blogger above, I made a parameter judgment, because my return button is customized, so I set a variable, only when the return button is clicked, the jump method in onUnload will not be called, so It will not cause onUnload to be called multiple times. Then the problem is solved.

If there is a friend who knows more about the reason for this problem, please leave a message.

Guess you like

Origin blog.csdn.net/qq_41687299/article/details/131050986