微信小程序引入外部js,并调用测试
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.测试调用
不用重来才叫快;能够积累才叫多