本文目錄一覽:
微信小程序wxs的使用(當頁面數據渲染前添加js操作)
小程序的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();
微信小程序wxml中使用js函數
上邊這種寫法不生效,在小程序中不支持這種語法。
需要創建一個wxs文件,
在wxml文件中引入該文件,並調用你想要用到的函數
微信小程序開發者工具page如何引用其他函數里的變數
直接調用函數名即可。
1、兩個頁面之間傳值,例如點擊A頁面跳轉到B頁面,把A頁面的變數傳到B頁面。
2、第一種方法在button上綁定一個點擊函數,代碼:我是A頁面。在對應的js文件裡面寫上跳轉代碼,並攜帶參數ID=3。點擊一下A頁面的button,在B頁面就可以收到值了,B頁面的options裡面是要接收的值。
原創文章,作者:PNVB,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/140136.html