小程序基础学习(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>
相关推荐
算法与编程之美23 分钟前
探究pytorch中多个卷积层和全连接层的输出方法
人工智能·pytorch·深度学习·神经网络·cnn
Master_oid34 分钟前
机器学习21:可解释机器学习(Explainable Machine Learning)(上)
人工智能·机器学习
MobotStone43 分钟前
边际成本趋近于零:如何让AI智能体"说得清、讲得明"
人工智能·架构
新智元1 小时前
李飞飞「世界模型」正式开放,人人可用! Pro 版首月仅 7 元
人工智能·openai
新智元1 小时前
GPT-5.1 凌晨突袭,奥特曼听劝!全网呼唤的人味回来了
人工智能
钅日 勿 XiName1 小时前
一小时速通Pytorch之自动梯度(Autograd)和计算图(Computational Graph)(二)
人工智能·pytorch·python
拓端研究室1 小时前
专题:2025中国医疗器械出海现状与趋势创新发展研究报告|附160+份报告PDF、数据、可视化模板汇总下载
大数据·人工智能·pdf
算家计算1 小时前
PaddleOCR-VL-vLLM-OpenAI-API使用教程来了!手把手教你搞定文档解析
人工智能·开源
算家计算1 小时前
GPT-5.1深夜发布却无惊喜?从GPT-5.1看大模型发展瓶颈
人工智能·chatgpt·openai
KWTXX2 小时前
组合逻辑和时序逻辑的区别
java·开发语言·人工智能