1. 新建一个.wxs文件
var filters={
toFix:function(val,count){
return val.toFixed(count);
}
}
module.exports={
toFix:filters.toFix
}
2.在wxml中写入wxs
<wxs module="filters" src="index.wxs"></wxs>
3.在需要规范小数点的地方用上这个过滤器
这里以数组为例
<view class="content">
<view class="pro" wx:for="{{proList}}">
<image src="/images/eleme.jpg"></image>
<view class="proName">{{item.listname}}</view>
<view class="proSalary">{{filters.toFix(item.listsalary,2) }}元/单</view>
</view>
</view>
4.前后效果对比
使用前:
使用后: