Home  >  Article  >  WeChat Applet  >  How to get started with WeChat mini program development? (Detailed explanation with pictures and text)

How to get started with WeChat mini program development? (Detailed explanation with pictures and text)

青灯夜游
青灯夜游forward
2020-04-03 09:43:564746browse

How to get started with WeChat mini program development? (Detailed explanation with pictures and text)

How to get started with WeChat mini program development? This article will introduce to you an introductory tutorial on WeChat applet development. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

                                                                                                                                                                  ’ ‐ to Receive Script ’ s             ‐   ‐ ‐ ‐‐ ‐‐ ‐                                                                                When developing any program, you must first find its official documentation. Let's first take a look at what official documentation it has.

The WeChat applet development document link is: https://mp.weixin.qq.com/debug/wxadoc/dev/index.html, as shown below:

Here are all the official documents for WeChat mini program development.

Now that we know the location of the document, let’s introduce how to develop a WeChat applet:

Step one: Download the WeChat applet developer tool and install it

, Download path:

https://mp.weixin.qq.com/debug/wxadoc/dev/devtools/download.html

After entering the download interface, according to your own operating system Select the corresponding link to download, and install it after the download is complete.

Second step: Login tool

After the developer tool is installed, we can open it. When opening it for the first time, you will need to scan the QR code to log in with WeChat, as shown below, Just scan it with your mobile phone WeChat and confirm your login.

Step 3: Create a project

Step 1: After successful login, the interface will be displayed as follows, click on the picture below At the " " sign, enter Step 2

Step 2: Fill in the project information, please see the picture below for instructions. After completing the filling, click "New" to complete a The project creation process. (If it is an existing project, that is, there is already a code file for the project, please click "Import Project" to import the existing project.)

Newly created projects will generate a demo code by default to show the code structure. The interface is as follows:

Step 4: Project Code structure explanation

#We can see that this project has been initialized and contains some simple code files. The most critical and essential ones are app.js, app.json, and app.wxss. Among them, the .js

suffix is ​​a script file, the

.json suffix is ​​a configuration file, and the

.wxss

suffix is ​​a style sheet file. The WeChat applet will read these files and generate applet instances. Let’s briefly understand the functions of these three files to facilitate modification and develop your own WeChat applet from scratch. 1. app.js is the script code of the mini program. We can monitor and process the life cycle functions of the applet and declare global variables in this file. Call the rich API provided by the framework, such as synchronous storage and synchronous reading of local data in this example. 2. app.json is the global configuration of the entire applet. In this file, we can configure which pages the mini program consists of, configure the window background color of the mini program, configure the navigation bar style, and configure the default title. Note that no comments can be added to this file.

3. app.wxss is the public style sheet of the entire applet. We can directly use the style rules declared in app.wxss on the class attribute of the page component.

We noticed that there are two folders in the code of the example program, one is pages and the other is utils, where utils is a folder for general tool class methods, and pages is where all pages are stored. folder. Let’s focus on this pages.

Step 5: Mini Program page file composition

In this example, we have two pages, the index page and the logs page , that is, the welcome page and the display page of the mini program startup log, they are both in the pages directory. The [path page name] of each page in the WeChat mini program needs to be written in the pages of app.json, and the first page in pages is the homepage of the mini program.

Each mini program page is composed of four different suffix files with the same name in the same path, such as: index.js, index.wxml, index.wxss, index.json. The file with the suffix .js is a script file, the file with the suffix .json is a configuration file, the file with the suffix .wxss is a style sheet file, .wxml The file with the suffix is ​​the page structure file.

index.wxml is the structure file of the page:

<!--index.wxml-->
<view class="container">
<view class="userinfo">
<button wx:if="{{!hasUserInfo && canIUse}}" open-type="getUserInfo" bindgetuserinfo="getUserInfo"> 获取头像昵称 </button>
<block wx:else>
<image bindtap="bindViewTap" class="userinfo-avatar" src="{{userInfo.avatarUrl}}" mode="cover"></image>
<text class="userinfo-nickname">{{userInfo.nickName}}</text>
</block>
</view>
<view class="usermotto">
<text class="user-motto">{{motto}}</text>
</view>
</view>

In this example, <view>, are used <image>, <text>,

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete