版权声明:欢迎转载但需要附上原博客链接 https://blog.csdn.net/qq_37746725?assign_skin=skin-ink https://blog.csdn.net/qq_37746725/article/details/80873646
1. 导出
1.1 方法和变量导出(写在被导出方法和变量的js文件)
-
module.exports = {
-
variable: value,
-
method : methodName
-
}
-
class tomModule {
-
constructor(url) {
-
this.url = url;
-
}
-
}
-
export { tomModule }
2.1 方法和变量的引入(写在需要引入其他js的方法或变量的JS文件中)
-
var util = require("../../../utils/util.js"); //注意这里引入的js文件路径写相对路径(绝对路径可能引入失败)
-
var home = require("../../../utils/home.js");
使用: util.method() 或 util.variable
2.2 class的引入
import { tomModule } from "../../../module/tomModule.js";//引入的js文件最好写相对路径
使用:
var tomModule = new tomModule(listUrl); //创建class对像后就可以直接调用对象的函数了。