原文:https://www.cnblogs.com/corgisyj/p/11039690.html
https://www.cnblogs.com/Skate0rDie/p/11275025.html
1.在 utils 目錄下 新建`filter.wxs`
var filters = {
toFix: function (value) {
return value.toFixed(2) // 此處2為保留兩位小數,保留幾位小數,這里寫幾
},
toStr: function (value) {
return value.toString()
},
toNum: function (value) {
return value.toNumber()
},
}
module.exports = {
toFix: filters.toFix,
toStr: filters.toStr,
toNum: filters.toNum,//暴露接口調用
}
2.在WXML中引入WXS
<wxs module="filters" src="../../utils/filters.wxs"></wxs>
3.在WXML中使用
<view>{{ filters.toFix(price) }}</view>