WXS微信小程序

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>
发布了34 篇原创文章 · 获赞 0 · 访问量 622

猜你喜欢

转载自blog.csdn.net/qq_44631273/article/details/104299210