<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                ## wxs > WXS(WeiXin Script)是小程序的一套腳本語言,結合 WXML,可以構建出頁面的結構。 注意 wxs 不依賴于運行時的基礎庫版本,可以在所有版本的小程序中運行。 wxs 與 javascript 是不同的語言,有自己的語法,并不和 javascript 一致。 wxs 的運行環境和其他 javascript 代碼是隔離的,wxs 中不能調用其他 javascript 文件中定義的函數,也不能調用小程序提供的API。 wxs 函數不能作為組件的事件回調。 由于運行環境的差異,在 iOS 設備上小程序內的 wxs 會比 javascript 代碼快 2 ~ 20 倍。在 android 設備上二者運行效率無差異。 示例 ~~~ <wxs module="m1"> var msg = "hello world"; module.exports.message = msg; </wxs> <view>{{m1.message}}</view> ~~~ ~~~ hello world ~~~ 數據處理 ~~~ // page.js Page({ data: { array: [1, 2, 3, 4, 5, 1, 2, 3, 4] } }) ~~~ ~~~ <!--wxml--> <!-- 下面的 getMax 函數,接受一個數組,且返回數組中最大的元素的值 --> <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> <!-- 調用 wxs 里面的 getMax 函數,參數為 page.js 里面的 array --> <view>{{m1.getMax(array)}}</view> ~~~ ~~~ 5 ~~~ 1.WXS 模塊 每一個 .wxs 文件和 <wxs> 標簽都是一個單獨的模塊 每個模塊都有自己獨立的作用域。即在一個模塊里面定義的變量與函數,默認為私有的,對其他模塊不可見。 一個模塊要想對外暴露其內部的私有變量與函數,只能通過 module.exports 實現。 ~~~ // /pages/tools.wxs const foo = "'hello world' from tools.wxs" const bar = function (d) { return d } module.exports = { FOO: foo, bar, } module.exports.msg = 'some msg' ~~~ ~~~ <!-- page/index/index.wxml --> <wxs src="./../tools.wxs" module="tools" /> <view>{{tools.msg}}</view> <view>{{tools.bar(tools.FOO)}}</view> ~~~ ~~~ some msg 'hello world' from tools.wxs ~~~ require函數 ~~~ const tools = require('./tools.wxs') console.log(tools.FOO) console.log(tools.bar('logic.wxs')) console.log(tools.msg) ~~~ module 屬性 module 屬性是當前 <wxs> 標簽的模塊名。在單個 wxml 文件內,建議其值唯一。有重復模塊名則按照先后順序覆蓋(后者覆蓋前者)。不同文件之間的 wxs 模塊名不會相互覆蓋。 module 屬性值的命名必須符合下面兩個規則: * 首字符必須是:字母(a-zA-Z),下劃線(_) * 剩余字符可以是:字母(a-zA-Z),下劃線(_), 數字(0-9) 2.變量 * WXS 中的變量均為值的引用。 * 沒有聲明的變量直接賦值使用,會被定義為全局變量。 * 如果只聲明變量而不賦值,則默認值為 undefined。 * var表現與javascript一致,會有變量提升。 命名規則 * 首字符必須是:字母(a-zA-Z),下劃線(_) * 剩余字符可以是:字母(a-zA-Z),下劃線(_), 數字(0-9) 保留字符串 ~~~ delete void typeof null undefined NaN Infinity var if else true false require this function arguments return for while do break continue switch case default ~~~ 3.注釋 WXS 主要有 3 種注釋的方法。 ~~~ <!-- wxml --> <wxs module="sample"> // 方法一:單行注釋 /* 方法二:多行注釋 */ /* 方法三:結尾注釋。即從 /* 開始往后的所有 WXS 代碼均被注釋 var a = 1; var b = 2; var c = "fake"; </wxs> ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看