第一步,在utils文件夹里新建一个filter.wxs文件
var replaceStar = function (index) { var a switch (index) { case '1': a = '出生时' break; case '2': a = '1月龄' break; case '3': a = '2月龄' break; case '4': a = '3月龄' break; case '5': a = '4月龄' break; case '6': a = '5月龄' break; case '7': a = '6月龄' break; case '8': a = '8月龄' break; case '9': a = '9月龄' break; case '10': a = '1岁6月龄' break; case '11': a = '2岁' break; case '12': a = '3岁' break; case '13': a = '4岁' break; case '14': a = '6岁' break; } return a; } module.exports = { replaceStar: replaceStar }
第二步,在需要的页面下使用
<wxs src="../../utils/filter.wxs" module="filter" /> <view class="time">{{filter.replaceStar(index)}}</view>