W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
WXS(WeiXin Script)是小程序的一套腳本語(yǔ)言,結(jié)合 WXML,可以構(gòu)建出頁(yè)面的結(jié)構(gòu)。
以下是一些使用 WXS 的簡(jiǎn)單示例:
<!--wxml-->
<wxs module="m1">
var msg = "hello world";
module.exports.message = msg;
</wxs>
<view> {{m1.message}} </view>
頁(yè)面輸出:
hello world
// page.js
Page({
data: {
array: [1, 2, 3, 4, 5, 1, 2, 3, 4]
}
})
<!--wxml-->
<!-- 下面的 getMax 函數(shù),接受一個(gè)數(shù)組,且返回?cái)?shù)組中最大的元素的值 -->
<wxs module="m1">
var getMax = function(array) {
var max = undefined;
for (var i = 0; i < array.length; ++i) {
max = max === undefined ?
array[i] :
(max >= array[i] ? max : array[i]);
}
return max;
}
module.exports.getMax = getMax;
</wxs>
<!-- 調(diào)用 wxs 里面的 getMax 函數(shù),參數(shù)為 page.js 里面的 array -->
<view> {{m1.getMax(array)}} </view>
頁(yè)面輸出:
5
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: