原生小程序 之 模块化 导入与导出
comom.js
function sayHello(name) {
console.log(`Hello ${name} !`)
}
function sayGoodbye(name) {
console.log(`Goodbye ${name} !`)
}
// 模块化的 两种导出方式
// module.exports.sayHello = sayHello
exports.sayHello = sayHello
exports.sayGoodbye = sayGoodbye
使用 commom.js
// index.js
const common = require("../common.js")
Page({
// 定义数据
data: {
},
onShow() {
common.sayHello('111')
common.sayGoodbye('222')
},
})