微信小程序——过滤器的模拟
>> 编写wxs文件——filter.wxs
//1. 价格格式化
function getPriceFormat(value) {
return parseFloat(isNaN(value) ? 0 : value).toFixed(2);
}
module.exports = {
getPriceFormat: getPriceFormat
}
>> wxml模板文件中导入过滤器文件:
<wxs module="filter" src="../../filter/filter.wxs"></wxs>
>> 在模板中使用过滤器:
<text class='c_price'>¥{{filter.getPriceFormat(item[index].price)}}</text>
个人原创博客,转载请注明来源地址:https://www.cnblogs.com/xyyt
浙公网安备 33010602011771号