当前位置:网站首页>[applet development] detailed explanation of host environment
[applet development] detailed explanation of host environment
2022-07-25 19:06:00 【Hua Weiyun】

Learning objectives of this section :
In depth understanding of the host environment composition of applets
@[toc]
1. The host environment of the applet
Mobile wechat is the host environment of small programs , Applets take advantage of the capabilities provided by the host environment , It can realize many functions that ordinary web pages cannot complete . for example : The applet calls the... Provided by wechat API Realize code scanning , Payment and other functions .
The content contained in the hosting environment of the applet :
- Communication model
- Operating mechanism
- Components
- API
2. Communication model
1. The subject of communication
The main body of communication in the applet is Render layer and Logic layer , among :
- WXML Templates and WXSS Styles work in the render layer
- JS Scripts work at the logical level
2. Communication model of applet
The communication model of the applet is divided into two parts :
- Render layer and Logic layer Communication between
- Logic layer and Third party servers Communication between
Both are forwarded through wechat clients
3. Operating mechanism
1. The startup process of the applet
- Download the code package of the applet to the local
- analysis app.json Global profile
- perform app.js Applet entry file , call App() Create an instance of the applet
- Rendering applet home page
- Applet startup completed

2. The process of page rendering
- Load the of the parsing page .json The configuration file
- To load a page .wxml Templates and .wxss style
- Execute the .js file , call Page() Create page instances
- Page rendering complete
4. Components
1. Classification of components in applet :
The components in the applet are also composed of Host environment Provided , Developers can quickly build a beautiful page structure based on components . Officials divide the components of small programs into 9 Categories: , Namely :
- View container
- Basic content </blue>
- Form components
- Navigation components
- Body assembly
- map Map components
- canvas Canvas components
- Opening ability
- Accessibility
2. Common view container class components
view
- Normal view area
- Be similar to HTML Medium div, Is a block level element
- Commonly used to achieve the layout effect of the page
for example : Use flex Achieve horizontal layout .
wxml Code :
<view class="container1"><view>A</view><view>B</view><view>C</view></view>wxss Code :
.container1 view{ width:100px; height:100px; text-align: center; line-height: 100px;}.container1 view:nth-child(1){ background-color: aquamarine;}.container1 view:nth-child(2){ background-color: azure;}.container1 view:nth-child(3){ background-color: darkorange;}.container1 { display: flex; justify-content: space-around;} Realization effect :
scroll-view
- Scrollable view area
- It is often used to achieve the effect of scrolling lists
utilize scroll-view Achieve the effect of scrolling up and down
wxml Code :
<scroll-view class="container1" scroll-y><view>A</view><view>B</view><view>C</view></scroll-view>Modified wxss Code :
.container1 { border:1px solid red; height:110px; /* Use scroll-view Set a fixed height */Realization effect :

swiper and swiper-item
- Carousel map container assembly and Shuffling figure item Components
Using these two components can achieve the effect of rotating pictures :
wxml Code :
<swiper class="swiper-container" indicator-dots="true" indicator-color="white" indicator-active-color="red" autoplay="true" interval="1000" circular><swiper-item><view class="item">A</view></swiper-item><swiper-item> <view class="item">B</view></swiper-item><swiper-item> <view class="item">C</view></swiper-item></swiper>wxss Code :
.swiper-container{ height:150px;}.item{ height:100%; line-height: 150px; text-align: center;}swiper-item:nth-child(1) .item{ background-color: aquamarine;}swiper-item:nth-child(2) .item{ background-color: azure;}swiper-item:nth-child(3) .item{ background-color: darkorange;} Realization effect :
3. Common basic content components
text
- Text component
- Be similar to HTML Medium span label , It's an in-line element
Long press the selected text content
<view> Long press to select the text content :<text user-select>HelloWorld!</text></view>
rich-text
- Rich text component
- Support HTML The string is rendered as WXML structure
hold HTML The string is rendered as the corresponding UI structure
<rich-text nodes="<h1 style='color:red'> title </h1>"> </rich-text>
4. Other common components
button
- Button components
- Functional ratio HTML Medium button Rich buttons
- adopt open-type Attribute can call various functions provided by wechat ( Customer service 、 forward 、 Get user authorization 、 Access to user information, etc )
image
- Picture components
- image The default width of the component is about 300px、 The height is about 240px
navigator
- Page navigation component
- Be similar to HTML Medium a link , Realize page Jump
5.API
In the applet API Is provided by the host environment , Through these rich applets API, Developers can easily call the capabilities provided by wechat , for example : Realize payment , Scan code and other functions .
Applet API Of 3 Big classification :
Event monitoring API
- characteristic : With on start , Used to monitor the trigger of some events
- give an example :wx.onWindowResize(function callback) Listen for window size changes
Sync API
- characteristic 1: With Sync At the end of the API It's all synchronous API
- characteristic 2: Sync API The results of the implementation of , You can get directly through the return value of the function , If the execution fails, an exception will be thrown
- give an example :wx.setStorageSync(‘key’, ‘value’) Write content to local storage
asynchronous API
- characteristic : Be similar to jQuery Medium $.ajax(options) function , Need to pass through success、fail、complete Receive the result of the call
- give an example :wx.request() Initiate a network data request , adopt success The callback function receives data
6. summary
In this section, we learned about the hosting environment of the applet and the specific contents of the hosting environment of the applet .
边栏推荐
- 聊聊sql优化的15个小技巧
- 李宏毅《机器学习》丨1. Introduction of this course(机器学习介绍)
- 【iniparser】项目配置工具iniparser的简单使用
- HTTP缓存通天篇,可能有你想要的
- Single arm routing experiment demonstration (Huawei router device configuration)
- Basic mode of music theory
- modelsim和quartus联合仿真PLL FIFO等IP核
- Yarn installation and use tutorial [easy to understand]
- 歌曲转调之后和弦如何转换
- 如何创建一个有效的帮助文档?
猜你喜欢

Alibaba cloud technology expert haochendong: cloud observability - problem discovery and positioning practice

MySQL sub query (selected 20 sub query exercises)

Pixel2Mesh从单个RGB图像生成三维网格ECCV2018

常用的开发软件下载地址

The second "future Cup" knowledge map championship was officially launched

Alibaba cloud technology expert Qin long: reliability assurance is a must - how to carry out chaos engineering on the cloud?

Fruit chain "siege": it's a journey of sweetness and bitterness next to apples

HTTP cache tongtianpian, there may be something you want

Care for front-line epidemic prevention workers, Haocheng JIAYE and Gaomidian sub district office jointly build the great wall of public welfare

2022 IAA industry category development insight series report - phase II
随机推荐
Microsoft azure and Analysys jointly released the report "Enterprise Cloud native platform driven digital transformation"
How to design product help center? The following points cannot be ignored
基础乐理之音程的度数
Basic music theory -- configuring chords
600000 pieces of data are made from March 1 to March 31. Videodate requires starting time from 00:00 to 24:00 on March 1 to 31, which is only for notes
The difference between QT exec and show
SQL realizes 10 common functions of Excel, with original interview questions attached
基于Mysql-Exporter监控Mysql
Software testing process (mind map)
Interface automation test platform fasterrunner series (IV) - continuous integration and solution of multi domain names
Yyds dry inventory interview must brush top101: reverse linked list
一个函数中写多少行代码比较合适呢? 代码整洁之道
Process communication (Systemv communication mode: shared memory, message queue, semaphore)
Talk about 15 tips of SQL optimization
Alibaba cloud technology expert Qin long: reliability assurance is a must - how to carry out chaos engineering on the cloud?
【小程序开发】常用组件及基本使用详解
srec_ Use of common cat parameters
网上商城系统MySql数据库设计项目实战
The second "future Cup" knowledge map championship was officially launched
qt exec和show的区别