本文目錄一覽:
-
1、微信小程序wxs的使用(當頁面數據渲染前添加js操作)
-
2、微信小程序wxml中使用js函數
-
3、微信小程序開發者工具page如何引用其他函數里的變量
微信小程序wxs的使用(當頁面數據渲染前添加js操作)
小程序的wxs功能可以讓wsmxl可以調用和編寫js,基本上wxs和JS無關系,只是語法形式很相似。愛掏網 - it200.com
如下寫了兩個關于時間的函數,并將它們導出,
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函數
上邊這種寫法不生效,在小程序中不支持這種語法。愛掏網 - it200.com
需要創建一個wxs文件,
在wxml文件中引入該文件,并調用你想要用到的函數
微信小程序開發者工具page如何引用其他函數里的變量
直接調用函數名即可。愛掏網 - it200.com
1、兩個頁面之間傳值,例如點擊A頁面跳轉到B頁面,把A頁面的變量傳到B頁面。愛掏網 - it200.com
2、第一種方法在button上綁定一個點擊函數,代碼:我是A頁面。愛掏網 - it200.com在對應的js文件里面寫上跳轉代碼,并攜帶參數ID=3。愛掏網 - it200.com點擊一下A頁面的button,在B頁面就可以收到值了,B頁面的options里面是要接收的值。愛掏網 - it200.com