<!--pages/three/three.wxml-->
<navigation-bar title="牧原" back="{{false}}" color="black" background="#FFF"></navigation-bar>
<wxs module="format">
function formatPrice(price){
return "$" + price
}
module.exports={
formatPrice:formatPrice
}
</wxs>
<view>
<block wx:for="{{book}}" wx:key="id" >
<view>
name:{{item.name}} ----price{{format.formatPrice(item.price)}}
</view>
</block>
</view>
data: {
book:[
{
"id":123,
"name":"牛马程序员",
"price":100
},
{
"id":1234,
"name":"牛马程序员4",
"price":1004
},
{
"id":1235,
"name":"牛马程序员5",
"price":1005
},
{
"id":1236,
"name":"牛马程序员6",
"price":1006
},
]
},
第二张方案吧wxs导出到外部文件
function formatPrice(price){
return "$" + price
}
module.exports={
formatPrice:formatPrice
}
再导入外部文件路径即可
<wxs module="format" src="/utils/format.wxs">
</wxs>