在utils目錄下新建common.js:
// common.js
function sayhello(name){
console.log(`hello,${name}!`)
}
module.exports = {
sayhello: sayhello
}
在index.js中引入common.js:
//index.js
//獲取應用實例
const app = getApp()
var common = require('../../utils/common.js')
Page({
data: {
},
//事件處理函數
bindViewTap: function() {
wx.navigateTo({
url: '../logs/logs'
})
},
onLoad: function () {
common.sayhello('china');
}
})