微信小程序 WXS模块 导出和使用

创建WXS模块

  ①在小程序页面下创建XX.wxs文件

   ②在XX.wxs文件中定义要使用的变量或方法

使用WXS模块

  ①导入XX.wxs文件

  ②使用模块内导出的内容

案例

创建WXS模块内容xx.wxs)

1 var countPrice = function oprice, nprice) {
2   return oprice - nprice).toFixed1)
3 }
4 
5 module.exports = {
6   countPrice:countPrice
7 }

使用WXS模块内容xx.wxml)

1 <wxs src="xx.wxs路径" module="模块变量名称"></wxs>
2 模块变量名称.countPricexx.oprice,xx.nprice)

时间若流水,恍惚间逝去

Published by

风君子

独自遨游何稽首 揭天掀地慰生平