小程序基础学习(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>
相关推荐
2301_7644413312 小时前
2026年1月至4月期间,大模型招投标市场态势
人工智能·语言模型·信息与通信
Thanwind12 小时前
从0开始的机器学习之旅(一):什么是机器学习
人工智能·机器学习
ChatInfo12 小时前
多模态检索开始进入工程期:用 Sentence Transformers 搭建可落地的 Multimodal RAG
人工智能
明月照山海-12 小时前
机器学习周报四十
人工智能·机器学习
ghie909012 小时前
隐马尔科夫模型(HMM)在语音识别领域的应用与代码实现
人工智能·语音识别
小墨同学boy12 小时前
越用越强不是广告语:拆解 Hermes Agent 的三层学习机制
人工智能·学习
kyle-fang12 小时前
主流微调工具
人工智能·语言模型
sunz_dragon12 小时前
Claude Code / Codex Git 版本管理完整使用指南
服务器·人工智能
Are_You_Okkk_12 小时前
中小型团队知识库搭建:AI开源实践方案
人工智能·开源
Figo_Cheung12 小时前
Figo 关于OntoGuard-CRE 技术白皮书——已在gitee上开源发布
人工智能·安全·gitee·开源·knowledge graph