免费国产欧美国日产_少妇AV一区二区三区无码_蜜桃精品av无码喷奶水小说_jk18禁网站视频_精产国品一二三级产品区别_被夫の上司に犯波多野结衣_78m成人手机免费看_最爽最刺激18禁视频_偷偷色噜狠狠狠狠的777米奇

易優(yōu)GEO 重磅上線 ~ 一站式GEO優(yōu)化工具,讓豆包、文心一言、DeepSeek 在回答中主動(dòng)推薦你的品牌,搶占AI流量入口!  點(diǎn)擊查看

小程序模板網(wǎng)

微信小程序?qū)嵗?-知乎日報(bào)小程序

發(fā)布時(shí)間:2017-12-27 11:17 所屬欄目:小程序開發(fā)教程

微信小程序開發(fā)文檔https://mp.weixin.qq.com/debug/wxadoc/dev/?t=20161107使用步驟下載微信小程序開發(fā)工具微信小程序注冊申請 ,獲取AppID(手機(jī)預(yù)覽需用到)服務(wù)器配置 ,添加合法域名,每個(gè)月只可修改3次 ,可添加 ...

 
 
 

 

微信小程序開發(fā)文檔


https://mp.weixin.qq.com/debug/wxadoc/dev/?t=20161107

使用步驟

  • 下載微信小程序開發(fā)工具
  • 微信小程序注冊申請 ,獲取AppID(手機(jī)預(yù)覽需用到)
  • 服務(wù)器配置 ,添加合法域名,每個(gè)月只可修改3次 ,可添加多個(gè)域名
  • 下載開發(fā)工具后創(chuàng)建項(xiàng)目,輸入申請的AppID,填寫項(xiàng)目名稱,導(dǎo)入該工程
  • 項(xiàng)目預(yù)覽體驗(yàn)
項(xiàng)目效果圖:

必須掌握的幾個(gè)知識(shí)點(diǎn)

目錄

  • 小程序配置
  • 小程序常用API接口

小程序配置

  • app.json文件小程序設(shè)置全局配置 ,包括頁面路徑、窗口、選項(xiàng)卡,以及網(wǎng)絡(luò)超時(shí)等
{
  "pages": [
    "pages/index/index",
    "pages/logs/index"
  ],
  "window": {
    "navigationBarTitleText": "Demo"
  },
  "tabBar": {
    "list": [{
      "pagePath": "pages/index/index",
      "text": "首頁"
    }, {
      "pagePath": "pages/logs/logs",
      "text": "日志"
    }]
  },
  "networkTimeout": {
    "request": 10000,
    "downloadFile": 10000
  },
  "debug": true
}
  • 通過appapp.js文件中App()來注冊一個(gè)小程序 提供了生命周期方法
App({
  onLaunch: function() { 
    // Do something initial when launch.
  },
  onShow: function() {
      // Do something when show.
  },
  onHide: function() {
      // Do something when hide.
  },
  globalData: 'I am global data'
})

通過全局的getApp()函數(shù),獲取小程序?qū)嵗?/p>

// other.js
var appInstance = getApp()
console.log(appInstance.globalData) // I am global data

注意:

App() 必須在 app.js 中注冊,且不能注冊多個(gè)。

不要在定義于 App() 內(nèi)的函數(shù)中調(diào)用 getApp() ,使用 this 就可以拿到 app 實(shí)例。

不要在 onLaunch 的時(shí)候調(diào)用 getCurrentPage(),此時(shí) page 還沒有生成。

通過 getApp() 獲取實(shí)例之后,不要私自調(diào)用生命周期函數(shù)。

  • 通過Page() 函數(shù)用來注冊頁面
//index.js
Page({
  data: {
    text: "This is page data."
  },
  onLoad: function(options) {
    // Do some initialize when page load.
  },
  onReady: function() {
    // Do something when page ready.
  },
  onShow: function() {
    // Do something when page show.
  },
  onHide: function() {
    // Do something when page hide.
  },
  onUnload: function() {
    // Do something when page close.
  },
  onPullDownRefresh: function() {
    // Do something when pull down.
  },
  onReachBottom: function() {
    // Do something when page reach bottom.
  },
  // Event handler.
  viewTap: function() {
    this.setData({
      text: 'Set some data for updating view.'
    })
  },
  customData: {
    hi: 'MINA'
  }
})

小程序常用API接口

  • wx.request https網(wǎng)絡(luò)請求
wx.request({
  url: 'test.php', //僅為示例,并非真實(shí)的接口地址
  method:"GET",
  data: {
     x: '' ,
     y: ''
  },
  header: {
      'content-type': 'application/json'
  },
  success: function(res) {
    console.log(res.data)
  }
})
  • 本地緩存

通過key的形式添加緩存setStorage (異步接口)

wx.setStorage({
  key:"key"
  data:"value"
})

通過key的形式獲取緩存getStorage (異步接口)

wx.getStorage({
  key: 'key',
  success: function(res) {
      console.log(res.data)
  } 
})

從本地緩存中異步移除指定 key

wx.removeStorage({
  key: 'key',
  success: function(res) {
    console.log(res.data)
  } 
})

清理本地?cái)?shù)據(jù)緩存

wx.clearStorage()
  • 顯示、隱藏消息提示框
wx.showToast({
  title: '加載中',
  icon: 'loading',
  duration: 10000
})

setTimeout(function(){
  wx.hideToast()
},2000)
  • 動(dòng)態(tài)設(shè)置當(dāng)前頁面的標(biāo)題
wx.setNavigationBarTitle({
  title: '當(dāng)前頁面'
})
  • 導(dǎo)航

保留當(dāng)前頁面,跳轉(zhuǎn)到應(yīng)用內(nèi)的某個(gè)頁面

wx.navigateTo({
  url: 'test?id=1'
})

關(guān)閉當(dāng)前頁面,跳轉(zhuǎn)到應(yīng)用內(nèi)的某個(gè)頁面

wx.redirectTo({
  url: 'test?id=1'
})
  • 獲取用戶信息,需要先調(diào)用 wx.login 接口
wx.getUserInfo({
  success: function(res) {
    var userInfo = res.userInfo
    var nickName = userInfo.nickName
    var avatarUrl = userInfo.avatarUrl
    var gender = userInfo.gender //性別 0:未知、1:男、2:女 
    var province = userInfo.province
    var city = userInfo.city
    var country = userInfo.country
  }
})
  • 設(shè)備

獲取網(wǎng)絡(luò)類型

wx.getNetworkType({
  success: function(res) {
    var networkType = res.networkType // 返回網(wǎng)絡(luò)類型2g,3g,4g,wifi
  }
})

獲取系統(tǒng)信息(異步接口)

wx.getSystemInfo({
  success: function(res) {
    console.log(res.model)
    console.log(res.pixelRatio)
    console.log(res.windowWidth)
    console.log(res.windowHeight)
    console.log(res.language)
    console.log(res.version)
  }
})

撥打電話

wx.makePhoneCall({
  phoneNumber: '1340000' //僅為示例,并非真實(shí)的電話號(hào)碼
})
  • 獲取當(dāng)前的地理位置、速度
wx.getLocation({
  type: 'wgs84',
  success: function(res) {
    var latitude = res.latitude
    var longitude = res.longitude
    var speed = res.speed
    var accuracy = res.accuracy
  }
})


易優(yōu)小程序(企業(yè)版)+靈活api+前后代碼開源 碼云倉庫:starfork
本文地址:http://m.szcjxy.com/wxmini/doc/course/18281.html 復(fù)制鏈接 如需定制請聯(lián)系易優(yōu)客服咨詢: 點(diǎn)擊咨詢
在線客服