微信小程式引入外部js,並呼叫測試
阿新 • • 發佈:2021-12-08
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.測試呼叫
不用重來才叫快;能夠積累才叫多