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://www.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>

        都昌县| 庄浪县| 阳西县| 遂宁市| 大田县| 苗栗市| 河池市| 玉龙| 沧州市| 密山市| 乐至县| 门头沟区| 丰城市| 乐陵市| 阿荣旗| 朝阳区| 徐闻县| 屏东市| 南丹县| 马龙县| 平潭县| 菏泽市| 重庆市| 沙河市| 通化县| 凤阳县| 漳州市| 临汾市| 巧家县| 登封市| 紫阳县| 龙井市| 洱源县| 镇原县| 景宁| 东乌| 涞水县| 梧州市| 南川市| 满洲里市| 辽阳市|