WXS微信小程序
目的:在WXML中是不能直接调用Page/Component中定义的函数的(实现Vue中的过滤功能)
第一种写在.wxml中
<wxs module="info">
var message = "hello world"
var name = "codewhy"
var sum = function(num1,num2){
return num1 + num2
}
module.exports = {
message:message,
name:name,
sum:sum
}
</wxs>
<view>{{info.message}}</view>
第二种抽离成文件info.wxs文件
function priceFormat(price,number){
var number = number || 2
return price.toFixed(number)
}
module.exports = {
priceFormat: priceFormat
}
<wxs src="./info.wxs" module="info"></wxs>
<view>{{info.priceFormat(32.7628,3)}}</view>