search
HomeWeChat AppletMini Program DevelopmentSimple example code for small program development

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) {

            }
        })
    }

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
  }
})

->Assignment

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

->Get used

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

【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!

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool