Home  >  Article  >  WeChat Applet  >  WeChat applet absolute path require

WeChat applet absolute path require

hzc
hzcforward
2020-06-05 09:39:334346browse

Before referring to the above article, you can implement the introduction of absolute paths, but in vscode, the require function cannot automatically prompt the path and the require module cannot automatically prompt

In order to solve this problem

1. Create the jsconfig.json file in the root directory

{  "compilerOptions": {   
         "target": "ES6", 
          "baseUrl": ".",  
          "paths": {  
             "/*": ["./*"]
            }
     }
}

2. When using the require function js Add

const app = getApp();
(function () { require = app.require; })();

at the beginning of the file. 3. Use

const CommonApi = require("/api/common");  
//可自动提示路径CommonApi.CallApi1(); //可以自动提示出方法 可配合d.ts食用

Recommended tutorial: "WeChat Public Account"

The above is the detailed content of WeChat applet absolute path require. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete