抖音开放平台Logo
开发者文档
控制台

require
收藏
我的收藏

any require(string path)

引入模块。返回模块通过 module.exports 或 exports 暴露的接口。

参数

名称

数据类型

描述

path

String

需要引入模块文件相对于当前文件的相对路径,不支持绝对路径

具体路径参考图片

**使用相对路径**

示例代码

// common.js function sayHello(name) { console.log(`Hello ${name} !`); } function sayGoodbye(name) { console.log(`Goodbye ${name} !`); } module.exports.sayHello = sayHello; exports.sayGoodbye = sayGoodbye;

// game.js 中 var common = require("./common/common.js"); common.sayGoodbye("test goodbye"); common.sayHello("test hello");

该文档是否有帮助?