小程序基础学习(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>
相关推荐
It's now1 小时前
Spring AI 基础开发流程
java·人工智能·后端·spring
Glad_R2 小时前
巧用AI流程图,让信息呈现更全面
人工智能·信息可视化·产品运营·流程图·产品经理
西南胶带の池上桜2 小时前
1.Pytorch模型应用(线性与非线性预测)
人工智能·pytorch·python
杀生丸学AI2 小时前
【无标题】VGGT4D:用于4D场景重建的视觉Transformer运动线索挖掘
人工智能·深度学习·3d·aigc·transformer·三维重建·视觉大模型
小和尚同志3 小时前
还在手动配置?这款开源软件让你一键配置 Claude Code 和 Codex
人工智能·aigc
阿正的梦工坊3 小时前
ProRL:延长强化学习训练,扩展大语言模型推理边界——NeurIPS 2025论文解读
人工智能·语言模型·自然语言处理
致Great3 小时前
Ollama 进阶指南
人工智能·gpt·chatgpt·agent·智能体
Nautiluss3 小时前
一起玩XVF3800麦克风阵列(八)
大数据·人工智能·嵌入式硬件·github·音频·语音识别
yzx9910133 小时前
人工智能大模型新浪潮:五大突破性工具深度解析
人工智能