創建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)