使用 场景
- 同一个页面展示两个数组,在js 中计算数组长度麻烦
- 可在wxml中进行操作
在wxml 中使用 (将其在wxml 文件中引入
)
<view class="item-info">
<view class="item-title">业主审核</view>
<wxs src="../../utils/calculate.wxs" module="tools" />
<view class="wait" wx:if="{{tools.calculate(new_list,new_list_gs)>0}}">待审核: {{tools.calculate(new_list,new_list_gs)}}</view>
</view>
创建 后缀为 wxs
的文件
function calculate(str1, str2) {
if (str1) {
return str1.length + str2.length
} else {
return '0'
}
}
module.exports = {
calculate: calculate
}