The javascript running environment of WeChat applet is different from that of the browser. The script logic of the page runs in JsCore, which is an environment without window objects. Therefore, window cannot be used in the script, and components cannot be operated in the script. There is no XmlhttpRequest object in JsCore, so jquery, zepto, axios cannot be used in the applet. This is when fly comes into play. You need to download wx.js (uncompressed) or wx.umd.min.js (compressed, 12k) from https://unpkg.com/flyio/dist/ or https://github.com/wendux/fly/tree/master/dist, and then copy it to your project directory.
use
If you are just a simple user, you don't need to read on, just stop here, don't close it in a hurry, come and star it before leaving https://github.com/wendux/fly. If you are interested in the principle, the following introduces the principle behind it. principle Fly's support for mini-programs is actually through a custom http engine. Let's take a look at the wx.js source code:
It can be seen that the key code is in adapter/wx. Let's take a look at the adapter code of the WeChat applet:
That's all the implementation, very simple! This example can help you understand the sentence "Fly supports different environments through different adapters". As for other environments, we can just follow suit. |
<<: Why does it only take 2 minutes to withdraw a WeChat message?
Suppose now, you write a copy for a product calle...
When you think of the college entrance examinatio...
Recently, the topic of influenza has been trendin...
The copywriting is obviously very well written, s...
In today's world, computers are indispensable...
Science Fiction Network, January 19 (Jin Kaiyi) T...
On December 8, my country's first novel coron...
Welcome to watch the science of the week. This we...
Recently, news about my country's plan to esta...
He Xiaopeng, chairman of Xpeng Motors, said: &quo...
Recently, the topic of “shared massage chairs” ha...
On August 27, 2014, an event known as the first f...
Review expert: Yin Tielun, deputy chief physician...
In October last year, the central bank issued the...
Compiled by: Gong Zixin According to data from th...