Home >WeChat Applet >Mini Program Development >Simple 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!