1.新建立js文件如圖

2.寫入相關方法並經行測試

const formatTime = date => { const year = date.getFullYear() const month = date.getMonth() + 1 const day = date.getDate() const hour = date.getHours() const minute = date.getMinutes() const second = date.getSeconds() return `${[year, month, day].map(formatNumber).join('/')} ${[hour, minute, second].map(formatNumber).join(':')}` } const formatNumber = n => { n = n.toString() return n[1] ? n : `0${n}` } function test(params) { console.log(123); } module.exports = { formatTime, test }
3.測試繼承
const util = require('../../utils/util');
Page({
/**
* 頁面的初始數據
*/
data: {
wx_login_title:'微信一鍵登陸',
phone_title:'手機號碼登陸'
},
/**
* 生命周期函數--監聽頁面加載
*/
onLoad: function (options) {
util.test();
},
wx_login_botton: function(e){
const url = '/pages/index/index';
getApp().authgetuserinfo(url);//微信登陸后
},
phone_login_botton: function(e){
console.log(this.data.phone_title);
wx.navigateTo({
url: '/pages/login/phone/phone_login?id=1'
})
}
})

4.測試調用

