小程序在wxml中使用js的方法

时间:2020-06-24 16:50:52   收藏:0   阅读:220

第一步:在utils中创建文件utils.wxs

// 作用于wxml中的函数
// 不支持ES6 的语法
var formatTime = function(ts) { var time = getDate(parseInt(ts)) var y = time.getFullYear() var m = time.getMonth() + 1 var d = time.getDay() console.log(ts,time, y,m,d) return y+‘/‘+m+‘/‘+d } module.exports = { formatTime: formatTime, }

 

第二步:在index.wxml中使用utils.wxs

<wxs src="../../utils/utils.wxs" module ="utils"/>

<text>{{utils.formatTime(time)}}</text>

  

原文:https://www.cnblogs.com/liucailing/p/13188200.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!