https://segmentfault.com/a/11...
以前参照上面文章 能够实现绝对路径的引入 可是在vscode中 require函数没法自动提示路径 而且require的模块也不能自动提示json
为了解决这个问题segmentfault
1.根目录创建 jsconfig.json
文件api
{ "compilerOptions": { "target": "ES6", "baseUrl": ".", "paths": { "/*": ["./*"] } } }
2.在使用 require
函数的js文件 最前面加上app
const app = getApp(); (function () { require = app.require; })();
3.使用函数
const CommonApi = require("/api/common"); //可自动提示路径 CommonApi.CallApi1(); //能够自动提示出方法 可配合d.ts食用