创建WXS模块
①在小程序页面下创建XX.wxs文件
②在XX.wxs文件中定义要使用的变量或方法
使用WXS模块
①导入XX.wxs文件
②使用模块内导出的内容
案例
创建WXS模块内容(xx.wxs)
1 var countPrice = function (oprice, nprice) { 2 return (oprice - nprice).toFixed(1) 3 } 4 5 module.exports = { 6 countPrice:countPrice 7 }
使用WXS模块内容(xx.wxml)
1 <wxs src="xx.wxs路径" module="模块变量名称"></wxs> 2 模块变量名称.countPrice(xx.oprice,xx.nprice)