小程序基础学习(wxs)

复制代码
<!--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>
相关推荐
百胜软件@百胜软件1 分钟前
从“人找货”到“货找人”:「胜券商品」如何用AI重构配补调
人工智能·重构
风流 少年5 分钟前
Spring AI 2.0:Advisor
android·人工智能·spring
zhangfeng113320 分钟前
[帮助聋哑人沟通]Tiger AI 手势识别大升级:从数字到无声世界,双手同时比划也能秒识别
人工智能
chunmiao303222 分钟前
Claude 文本水印引退订,AI 内容溯源时代要来了
人工智能
维核科技35 分钟前
AI+智慧农业:从选种到丰收的AI赋能之路
人工智能
killerbasd1 小时前
总结 8。15
人工智能·机器学习·概率论
数智化转型推荐官1 小时前
AI驱动采购全链路革新:泛微·京桥通智能化采购管理方案深度解读
人工智能
Microsoft Word1 小时前
Agent上下文工程构建
人工智能
段一凡-华北理工大学1 小时前
AI推动工业智能化转型~系列文章24:钢铁工业 AI 全景图:从原料场到轧机的场景地图
人工智能·深度学习·模型生命周期·钢铁工业·ai全景
styshoo1 小时前
[NVSentinel] gpu-health-monitor模块调研
人工智能·云原生·nvsentinel