- 在 utils 下创建 .wxs 文件,里面封装方法并导出
var week = function (year,month,day) { var flag = getDate(year,month - 1,day).getDay() switch(flag){ case 0: return '周日'; case 1: return '周一'; case 2: return '周二'; case 3: return '周三'; case 4: return '周四'; case 5: return '周五'; case 6: return '周六'; } } module.exports = { week: week }
- 在要使用的 .wxml 页面引入,module 属性的值可以自定义
<wxs module="week" src="../../utils/week.wxs"></wxs>
- 在要使用的 .wxml 页面使用,使用要在引入之后
<text style="margin-left: 8px;">{{week.week(year,month,index + 1)}}</text>
- ok~
在.wxml文件中使用方法
声明:此资源由本博客收集整理,只用于记录心得和交流学习,请勿用作它途。如有侵权,请联系, 删除处理。