xyyt

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

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

分类:

技术点:

相关文章: