首页 > 编程知识 正文

微信小程序引用js函数,微信小程序能调用js么

时间:2024-04-24 11:43:26 阅读:334288 作者:AIZA

本文目录一览:

微信小程序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里面是要接收的值。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。