当前位置:网站首页>[wechat applet] how to build a building block development?
[wechat applet] how to build a building block development?
2022-07-01 06:32:00 【Front end Xiao Liu is not afraid of cattle】
List of articles
We explained the code composition of the project above , Understand the function of each file, language type and web The difference between web development languages .
Today, let's discuss the building block development of wechat applet , In fact, we don't need to write the underlying code of some functions , Just use a few lines of code to call the functions of wechat environment , To implement our complex applications , Improve the efficiency of our developers .
One , Host environment
In mobile terminal , We know that it can be divided into Android The environment and iOS Environmental Science , Their functions cannot be shared , Like Android WeChat APP stay iOS The end cannot be executed .
These are like APP The implementation of the environment depends on some functions provided by the environment .
Our small programs rely on the environment of mobile wechat
With the help of the host environment of mobile wechat , Realize some functions that ordinary web pages cannot realize , As we are familiar with wechat payment 、 Geographical location, etc , Of course, if your mobile phone doesn't have wechat , Applets cannot rely on this environment , It is also impossible to execute .
Mobile wechat provides the applet with functions in four directions
- Communication model
- Operating mechanism
- Components
- API
Two , Communication model
First, we need to understand the two concepts of render layer and logic layer :
- WXSS and WXML Work on the render layer , Leave it to
webviewRendering , There are multiple... In the render layerwebviewThreads ; - JS Working at the logical level , from
JScoreThread running JS Script . The two are separate , That is, we mentioned in the previous chapter that the pursuit of rendering is separated from logic MVVM Pattern .
Wechat applet has two types of communication , as follows :
- One is the communication between rendering layer and logic layer , There is a wechat client between the two (
Native) Forward - The second is the communication between the logical layer and the third-party server , Sometimes we need to pull the server data from the applet , Or data response to the third-party server , At this time, we also use wechat client (
Native) forward .
Such as HTTP request and Web socket Represent data request and data response respectively .
3、 ... and , Operating mechanism
Complete execution of a small program , What is the operating mechanism of wechat client ? Understanding these can help us better develop small programs .
First, before the wechat client opens the applet , Will download the entire applet code package to the local .
Then it will pass app.json Go and get the documents inside pages Field , So as to get all the page paths of your current applet .
Remember pages Is there anything in it ?
{
"pages":[
"pages/index/index",
"pages/logs/logs"
]
}
In this configuration , The applet will put the first line of the page path, that is index The corresponding page serves as the home page , As the first page we open the applet .
After the applet starts , Wechat clients will go to app.js file , That is, the entry file of the project , Instantiate a small program ,App Example of onlaunch Events trigger , Execute callback function .
App({
onLaunch: function(){
// Code
}})
Since you want to display the page , The wechat client will reprint the code of the home page first , Then go to the... Under the page .json The configuration file , Then reprint the page WXML and WXSS File to render the page .
Finally, the client will reprint .js Entrance file , adopt Pages Function instantiates a page ,Pages The function generally contains data Paragraph and onload Event callback function , As shown below :
Pages({
data: {
// Data involved in page rendering
logs: []
},
onLoad: function(){
// onload event , Execute the function after page rendering
}
})
data Store the data involved in the rendering of the page in , These data need to be bound in the rendering layer .
onLoad The event is triggered after the page is loaded, that is, after rendering , Then call the callback function inside .
Four , Components, components
We can understand it as , Wechat provides us developers with some convenient ways to make complex functions , like WXML Medium <map></map> label , Just this line of code , We can display the map in the page , Even after we add some attribute value settings , A map showing a specific location .
such , We can use the components provided by wechat like building blocks , Make some complicated pages , Realize advanced functions , Is it very human !
In the next chapter, we will start to learn and practice the view component !
5、 ... and ,API
Provide some unique functions , Such as obtaining user information 、 Wechat payment and so on , We developers can use API Use it directly .
For example, we need to call wechat scanning function , We can directly :
wx.scanCode({
success: (res) => {
console.log(res)
}
})
Similar to components , It's just API Relatively, it can provide more complex functions , because API In fact, it is equivalent to calling the built-in function of wechat environment to realize the function , Wechat applet encapsulates some source code that can complete some functions , As API For developers .
This is the end of today's small program , If it helps you , You can pay attention to the follow-up updates of Niuniu , Thank you for your support !
Debt see ~
边栏推荐
- C how to print out the original array
- 数据库对象:视图学习记录
- 绕圆旋转动画组件,拿过来直接用
- 软件工程复习
- Functions of switch configuration software
- [ManageEngine Zhuohao] what is network operation and maintenance management and what is the use of network operation and maintenance platform
- H5网页判断是否安装了某个APP,安装则跳转未安装则下载的方案总结
- 做技术,自信不可或缺
- Interview questions for HW (OD) post
- Three minutes to quickly understand the whole process of website development
猜你喜欢

C language course set up property fee management system (big work)

NOC 设计的一些坑

Discrimination between left and right limits of derivatives and left and right derivatives

ManageEngine Zhuohao helps you comply with ISO 20000 standard (IV)

Teach you how to implement a deep learning framework

C语言课设工资管理系统(大作业)

To sort out the anomaly detection methods, just read this article!
![[ManageEngine] how to realize network automatic operation and maintenance](/img/8a/75332d3180f92c6a6482d881032bbf.png)
[ManageEngine] how to realize network automatic operation and maintenance

【Unity Shader 描边效果_案例分享第一篇】

SQL statement
随机推荐
DML statement in SQL (data operation language)
JSON module
高阶-二叉平衡树
Idea easy to use plug-in summary!!!
Chapter V input / output (i/o) management
sql中TCL语句(事务控制语句)
存储过程学习笔记
H5网页判断是否安装了某个APP,安装则跳转未安装则下载的方案总结
[unity shader custom material panel part I]
谷粒商城-环境(p1-p27)
数据库产生死锁了请问一下有没有解决办法
[ManageEngine Zhuohao] what is network operation and maintenance management and what is the use of network operation and maintenance platform
高阶-二叉搜索树详解
Minio error correction code, construction and startup of distributed Minio cluster
Mongodb: I. what is mongodb? Advantages and disadvantages of mongodb
HCM Beginner (III) - quickly enter pa70 and pa71 to browse employee information PA10
SQL学习笔记2
Picture server project test
[unity shader amplify shader editor (ASE) Chapter 9]
异常检测方法梳理,看这篇就够了!