微信小程序——过滤器的模拟

>> 编写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>

posted on 2018-03-08 14:42  逍遥云天  阅读(2763)  评论(0)    收藏  举报

导航