problem description
js in Mini Program, you can write a js as a module file, and then introduce it in the corresponding js file with require, but there are some modules that I need to use in a lot of js files, in that case, it is particularly troublesome to introduce into each js file, is there any way to introduce it in app.js and then use it directly in other js files.
the environmental background of the problems and what methods you have tried
I have tried to introduce it into the app.js file ( const requestTool = require (". / config.js")
). After introducing the module, I wrote down the requestTool, in the App of app.js and can be used in other js files through app.requestTool (app from getApp ()). I want to know if there is a better way to achieve this function.
related codes
app.js
const requestTool = require("./config.js");
// import requestTool from "./config.js"
//app.js
App({
requestTool,
other js files
const app = getApp ();
app.requestTool