Unicloud develops WeChat applets - the use of cloud public modules

I. Overview

The cloud public module can be understood as a storage space for public variables and methods.
It can be understood as an npm library, but the library is placed on our developers' side. When a module wants to use this library, it is installed and used (similar to using the npm library), the only difference is that it uses the commonjs module management solution.

Second, write a public module

insert image description here
After right-clicking on the common folder - creating a new common module, you can start writing the common module.
For example, if I need a module that saves public information such as appid, I can write like this:

const APPID='xxx'
const APPSECRET='xxx'
module.exports = {
    
    
	APPID,
	APPSECRET
}

Third, introduce and use a common module

insert image description here
Then import it and use it:

const {
    
    APPID,APPSECRET}=require("set-config")

Guess you like

Origin blog.csdn.net/weixin_42349568/article/details/128323775