Wechat small program development skills (continue to update ing)
-
All pages need to be registered in the pages array in the app.json file in the “path/file name” format.
Note: You do not need to add a filename extension
-
The first page in the Pages array in app.josn is the start page of the applet
-
The JS, JSON, WXML, WXSS of each page can be different from the directory name, but must have the same path and file name
-
Page directories can be nested and registered in app.json according to the page directory
-
Global variables in app.js can be modified by direct assignment, but Page variables need to be modified using the page.prototype.setData () method, and the assigned data cannot exceed 1024 kB
-
When importing modules into a file, require uses a relative path to import them (absolute paths will give an error)
-
To import multi-level files, use the following methods:
Fun1 = function(){// code} fun2 = function(){// code} module.export = {fun1: fun1, fun2: Var funcs = require('func.js ') util = function(){// code} util = function(){// code} module.export = { fun1: funcs.fun1, fun2: funcs.fun2, util: util }
Copy the code
-
Applet WXSS import files using @import should use relative paths
-
The priority of WXSS style in applets is inline style > external style > global style
-
Most of the attributes of CSS3 are supported in the WXSS style file of the applet, but the selector support is limited
Component part
-
is a wrapper element only, subject to attribute control and cannot be nested and will not be rendered
-
components can only be nested within a
component
-
Only content in the
component supports long-press selection
-
The range array subscripts in the
component must be consecutive and start at 0, otherwise the option will be null -
Component names are all lowercase, and all uppercase component names are converted to lowercase at rendering time
-
Any custom component < custom name > will be rendered as a
component, but be careful not to have a number in the component name. (Although semantic components can be customized, they are not recommended because wechat official did not explain them.)
-
Using the Page tag selector, you can modify the style of the top-level node, which is equivalent to the element in HTML
-
The address of request, upload, download and websocket in the program must be HTTPS, and the legal domain name must be registered on the wechat public platform of the current APPID
-
{‘content-type’: ‘application/x-www-form-urlencoded’} {‘content-type’: ‘application/ x-w-form-urlencoded ‘}
-
There are usually two ways to use global data in some cases: setting global variables and writing to the cache. The difference is that global variables have the same lifetime as applets, whereas caches are stored permanently
-
Wx.login () only returns the login code, which can be sent to the wechat server to obtain the user’s session_key and OpenID. Wechat official provides the login status check interface and a set of authentication mechanism, please click the official document
-
The local cache of applets cannot exceed 10M
-
During the upload and download of the small program, only the key of the file can be obtained. The developer obtains the binary content of the file through the key on the server side.
Tool parts
-
Modifying the WXML and WXSS files will refresh the page
-
Modifying the JS and JSON files will recompile the applet
-
Adding the target page to the app.json file Pages array will automatically generate the page directory and required files
-
Item – Basic Information If the development environment does not verify the request security domain name and TLS version, the HTTP request address can be used to facilitate local debugging
-
You can quickly view the security domain name configured for the current APPID in item – Configuration
-
During mobile phone debugging, you can tap in the upper right corner and select Enable Debug to enable mobile phone debugging
-
Project – Preview can add preview page and parameter information, skip tedious foreplay to the location you want to operate
-
shortcuts
formatting
Ctrl+S: Save file Ctrl+[, Ctrl+] : Indent code line Ctrl+Shift+[, Ctrl+Shift+] : Collapse open code block Ctrl+C Ctrl+V: Copy and paste, if no text is selected copy and paste a line Shift+Alt+F: Code formatting Alt+Up, Alt+Down: Move a line Up and Down Shift+Alt+Up, Shift+Alt+Down: Copy a line Up and Down Ctrl+Shift+Enter: Insert a line above the current line Ctrl+Shift+F: global search
Copy the codeThe cursor associated
Ctrl+End: Move to the End of the file Ctrl+Home: Move to the beginning of the file Ctrl+ I: Select the current line Shift+End: Select from the cursor to the End Shift+Home: Select from the beginning of the line to the cursor Ctrl+Shift+L: Select all matches Ctrl+D: Select match Ctrl+U: cursor rollback
Copy the codeInterface related
Ctrl + m: Open or hide the emulator
Copy the code
-
Applets are package-based, and the development and distribution process is very different from that of H5 applications
-
The session management part of Web development in the mini program is realized by wechat server
-
The domain name of the applet is only used for communication and authentication. There is no Cookie mechanism
What do you think of Zhang Xiaolong’s statement about wechat small program in 2017? What is the value of wechat small program (application number)?