1. <ul id="0c1fb"></ul>

      <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
      <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区

      RELATEED CONSULTING
      相關(guān)咨詢
      選擇下列產(chǎn)品馬上在線溝通
      服務(wù)時(shí)間:8:30-17:00
      你可能遇到了下面的問題
      關(guān)閉右側(cè)工具欄

      新聞中心

      這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
      小程序中什么是模塊化

      這篇文章將為大家詳細(xì)講解有關(guān)小程序中什么是模塊化,小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。

      創(chuàng)新互聯(lián)主營馬鞍山網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,重慶App定制開發(fā),馬鞍山h5重慶小程序開發(fā)搭建,馬鞍山網(wǎng)站營銷推廣歡迎馬鞍山等地區(qū)企業(yè)咨詢

      文件作用域
      在JavaScript文件中聲明的變量和函數(shù)只在該文件中有效;不同的文件中可以聲明相同名字的變量和函數(shù),不會(huì)互相影響。
      通過全局函數(shù)getApp()可以獲取全局的應(yīng)用實(shí)例,如果需要全局的數(shù)據(jù)可以在App()中設(shè)置,如:

      // app.js  
      App({  
       globalData: 1  
      })
      // a.js  
      // The localValue can only be used in file a.js.  
      var localValue = 'a'  
      // Get the app instance.  
      var app = getApp()  
      // Get the global data and change it.  
      app.globalData++
      // b.js  
      // You can redefine localValue in file b.js, without interference with the localValue in a.js.  
      var localValue = 'b'  
      // If a.js it run before b.js, now the globalData shoule be 2.  
      console.log(getApp().globalData)

      模塊化
      我們可以將一些公共的代碼抽離成為一個(gè)單獨(dú)的js文件,作為一個(gè)模塊。模塊只有通過module.exports才能對外暴露接口。

      // common.js  
      function sayHello(name) {  
       console.log('Hello ' + name + '!')  
      }  
      module.exports = {  
       sayHello: sayHello  
      }

      在需要使用這些模塊的文件中,使用require(path)將公共代碼引入。

      var common = require('common.js')  
      Page({  
       helloMINA: function() {  
       common.sayHello('MINA')  
       }  
      })

      關(guān)于“小程序中什么是模塊化”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),請把它分享出去讓更多的人看到。


      新聞標(biāo)題:小程序中什么是模塊化
      標(biāo)題來源:http://ef60e0e.cn/article/jhciij.html
      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区
      1. <ul id="0c1fb"></ul>

        <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
        <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

        朝阳市| 安龙县| 佳木斯市| 乾安县| 千阳县| 西藏| 大同市| 延吉市| 久治县| 六枝特区| 滕州市| 噶尔县| 信阳市| 广昌县| 涟水县| 金沙县| 望奎县| 天镇县| 清丰县| 沈丘县| 彭泽县| 湖北省| 安福县| 阿拉善左旗| 阜康市| 和平县| 绥阳县| 清徐县| 涟源市| 安丘市| 永州市| 建昌县| 明光市| 连云港市| 万年县| 新巴尔虎左旗| 淮安市| 柳林县| 海伦市| 淮阳县| 海原县|