解决微信小程序 wxml文件无法使用js方法

1,644 阅读1分钟

1.新建wxs文件。

fliters.wxs   

//价格强制保留两位小数
function toFix(value) {
  // var v = parseInt(value)//强转Int  
  if (value == undefined) {
    value = 0  
}  
return value.toFixed(2) //此处2为保留两位小数}
module.exports = {
  toFix: toFix
}

2.wxml页面引用文件

<!-- 引用处理函数 -->
//路径为相对路径<wxs src="../filters.wxs" module="filters"></wxs>


3.使用

<text>{{'¥' + filters.toFix(orderinfo.tradingPrice)}}</text>