
2、小程序的JS有一些额外的成员
App方法 用于定义应念告用程序实例对象
Page方法 用于定义页面对象
getApp方法 用于获取全局应用程老颂序对象
getCurrentPages方法 用来获取当前页面的调用栈(数组 最后一个就是当前页
wx对象 用来提供核心api的 官方侍高郑链接: https://developers.weixin.qq.com/miniprogram/dev/api/
3、小程序JS是支持CommonJS规范的
eg:
./utils/foo.js文件
function say(msg){
console.log("hello"+msg)
}
module.exports = {
say:say
}
app.js文件
const foo = require("./utils/foo.js")
foo.say("hi")
工具/原料
微信小程序 web-view
方法/步骤
1、打开微信开发者工具。
2、选择新建小程序。
3、输入项目信息锋银后,点击”确定“。
4、进入开发画面。
5、点击”index wxml“右侧将其他代码都删除,在容器中,添加”web-view“。
6、给这个web-view添加src属性这里做基陪添加需要的地址即可。
7、完成后保存修改,在左侧的手机模拟器中,即可查看纯蠢效果。
小程序的wxs功能可以让wsmxl可以调用和编写js,基本上wxs和JS无关系,只是语法形式很相似。
如下写了两个关于时间的函数,并将它们导出,
<wxs module="敬桥昌m1">亮扒
var getMax = function(flightDate) {
var now = getDate().getDate()
var flDate = getDate(flightDate).getDate()
if( now <flDate ){
return '+1'
}else{
return ''
}
}
var formartTime = function(flightDate,format){
if(flightDate){
var realDate = getDate(flightDate)
function timeFormat(num) {
return num <10 ? '0' + num : num
}
var date = {
"Y": timeFormat(realDate.getFullYear()),
"M": timeFormat(realDate.getMonth() + 1),
"d": timeFormat(realDate.getDate()),
"h": timeFormat(realDate.getHours()),
"m": timeFormat(realDate.getMinutes()),
"s": timeFormat(realDate.getSeconds()),
"q": Math.floor((realDate.getMonth() + 3) / 3),
"S": realDate.getMilliseconds(),
}
if (!format) {
format = "yyyy-MM-dd hh:mm:ss"
}
if( format == 'hh:mm' ){
return date.h+':'+date.m
}else{
return date.h+':'+date.m
}
}else{
return false
}
}
module.exports.getMax = getMax
module.exports.formartTime = formartTime
</消行wxs>
可在页面添加如下使用:
m1.formartTime() m1.getMax()
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)