前言:
在微信小程序的wxml中可以在{{}}进行里进行简单的三目运算。但是复杂的parseInt()、str.split()、num.toFixed()等在{{}}里是无效的。本文旨在解决这个问题
1.在wxml中执行复杂运算
<wxs module="fn">
module.exports = {
parseInt:function(num){
return "约"+parseInt(num)
},
split:function(str){
return str.split(",")
},
toFixed:function(num){
return (num).toFixed(2)
}
}
</wxs>
<view>
<view class='num'>{{amount>10000?fn.parseInt(amount/10000):amount}}</view>
<text class='text'>消费额({{amount>10000?"万元":"元"}})</text>
</view>
2.在模板的wxml中执行复杂运算
<template name="ordersTmp">
<view class="ordersTmpBox">
<view class="detail"> 消费额:{{fn.parseInt(amount/10000)}}万元</view>
</view>
<wxs module="fn">
module.exports = {
parseInt:function(num){
return "约"+parseInt(num)
},
split:function(str){
return str.split(",")
},
toFixed:function(num){
return (num).toFixed(2)
}
}
</wxs>
</template>
本文介绍如何在微信小程序的WXML中执行复杂运算,如parseInt(), str.split(), num.toFixed()等,通过自定义wxs模块实现金额显示的转换。
1408

被折叠的 条评论
为什么被折叠?



