小程序基础学习(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>
相关推荐
ygy.白茶7 分钟前
从电影分类到鸢尾花识别
人工智能
AI_gurubar3 小时前
大模型教机器人叠衣服:2025年”语言理解+多模态融合“的智能新篇
人工智能·机器人
XINVRY-FPGA5 小时前
EPM240T100I5N Altera FPGA MAX II CPLD
人工智能·嵌入式硬件·fpga开发·硬件工程·dsp开发·射频工程·fpga
HuggingFace5 小时前
开源开发者须知:欧盟《人工智能法案》对通用人工智能模型的最新要求
人工智能
媒体人8886 小时前
GEO 优化专家孟庆涛:技术破壁者重构 AI 时代搜索逻辑
大数据·人工智能
小菜AI科技7 小时前
Windsurf 评测:这款 人工智能 IDE 是你需要的颠覆性工具吗?
人工智能
RaymondZhao347 小时前
【全面推导】策略梯度算法:公式、偏差方差与进化
人工智能·深度学习·算法·机器学习·chatgpt
yzx9910137 小时前
小程序开发APP
开发语言·人工智能·python·yolo
AKAMAI7 小时前
通过自动化本地计算磁盘与块存储卷加密保护数据安全
人工智能·云计算
无规则ai8 小时前
动手学深度学习(pytorch版):第四章节—多层感知机(5)权重衰减
人工智能·pytorch·python·深度学习