起楚永世承,教崇忠孝,志尚宽平
清醒时做事,迷茫时读书,独处时思考,烦躁时运动,得意时淡然,失意时坦然,忙碌时专注,闲暇时蓄力。

微信小程序引入外部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.测试调用

 

posted @ 2021-12-08 14:17  一蹴而就  阅读(1796)  评论(0编辑  收藏  举报