Simple example code for small program development

零下一度
Release: 2017-05-25 17:43:51
Original
5596 people have browsed it

Recently I am developing a WeChat applet application. I also started from scratch and sorted out the areas that needed attention during the development process.

this scope

This may not report an error because of the definition when debugging, which makes debugging very troublesome, so pay special attention to it

onLoad: function () {
        var that = this
        wx.request({
            url: 'https://域名/AppService/UserHandler.ashx', 
            data: {
                
            },
            method: 'GET',
            header: {
                'Content-Type': 'application/json'
            },
            success: function (res) {
                that.setData({
                    
                })
            },
            fail: function (res) {

            }
        })
    }
Copy after login

Asynchronous

request is an asynchronous request, so the return value of the same level function, a request, and a get request cannot be obtained. , you need to use the callback function

TLS version

When requesting data, you will be prompted that a TLS version cannot be higher than 1.0, put " "Development environment does not verify the requested domain name and TLS version" check

https

The mini program only supports https bound to the domain name, and in the mini program management interface request for configuration

Global variables

->Definition

//app.js
App({
  onLaunch: function () {

  },
  globalData: {
    userInfo: null
  }
})
Copy after login

->Assignment

//index.js
//获取应用实例
var app = getApp()
Page({
  data: {
    userInfo: {}
  }
})
Copy after login

->Get used

//user.js
//获取应用实例
var app = getApp()
Page({
    // 页面初始数据
    data: {
        userInfo: null
    },
    onLoad: function () {
        this.setData({
            userInfo: getApp().globalData.userInfo,
        })
    }
})
Copy after login

【Related recommendations】

1. Complete source code download of WeChat mini program

2. Chai Ge WeChat mini program application store source code

3. WeChat mini program demo: Yangtao

The above is the detailed content of Simple example code for small program development. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!