当前位置:网站首页>Practical development of member management applet 06 introduction to life cycle function and user-defined method
Practical development of member management applet 06 introduction to life cycle function and user-defined method
2022-07-06 04:06:00 【Low code preacher】
In the previous section, we introduced the design idea of permission , And it introduces CSS The box model of . In this section, we will introduce life cycle functions and custom methods .
Low code introduction
In previous versions, you can add custom methods to the data source , You can write your own background logic . The new version splits the data source into three menus , They are data models 、 Connectors and custom connectors . In the previous chapter, we introduced how to create a custom connector . In this section, we will introduce how to call a custom connector in the low code editor .
Students who are new to low code development may not have a special understanding of the concept of low code . Low code is a business term , It is compared with the whole code , It means less code . But generally, our processing logic still needs to write code , The code written here is called low code .
What technology is low code used ? Low code is used javascript The grammar of , The basis here refers to the need to master javascript Basic knowledge of . For beginners, I suggest learning in the rookie tutorial , The tutorial is relatively basic, suitable for beginners to master basic concepts .
Low code operation
Where to write low code ? Enter the application , Find the six dot icon on the left side of the navigation bar , Click low code editor
The low code editor is divided into three parts ,style、lifecycle and handler. among style、lifecycle It is also divided into the difference between global scope and page scope . The global scope is that all pages can be used , Page range only works on the current page .
stay style You can write style codes in
We usually use class selectors to define styles , Grammar starts with a dot , The following English is the name of the class selector , You can name yourself . It is usually recommended to use meaningful names , Facilitate the understanding of subsequent codes .
After the style is defined, it can be used on components , For example, select common container components , Switch to style label
Find the custom section , You can choose different classes
If a custom style class is set on the component , In the outline tree view of the component, a CLS The icon , This component has been set with style class
Why define styles in style files ? This is mainly for code reuse and maintainability . If the same style is used in many places , Then we abstract the common part into the style file , Each component can be selected only once . Another advantage is that if we modify the style in the style file , Then all the components applied to this style have changed , It saves every component from being modified repeatedly .
Introduction to life cycle function
There is a concept of life cycle in micro architecture , Generally, small programs go through a series of life cycles from creation to destruction . For the sake of understanding , We can take a look at the life cycle of low code
Different logic can be implemented in different life cycle functions , For example, in the global life cycle, we can call the custom connector to get openid, And will openid Assign a value to the global variable, and the subsequent pages can be used .
The global lifecycle function code is as follows
/** * It can be done by app Get or modify the global application Variable state Etc * The details can be console.info In the editor Console Panel for more information * if necessary async-await, Please before the method async **/
export default {
onAppLaunch(launchOpts) {
//console.log('---------> LifeCycle onAppLaunch', launchOpts)
},
onAppShow(appShowOpts) {
//console.log('---------> LifeCycle onAppShow', appShowOpts)
},
onAppHide() {
//console.log('---------> LifeCycle onAppHide')
},
onAppError(options) {
//console.log('---------> LifeCycle onAppError', options)
},
onAppPageNotFound(options) {
//console.log('---------> LifeCycle onAppPageNotFound', options)
},
onAppUnhandledRejection(options) {
//console.log('---------> LifeCycle onAppUnhandledRejection', options)
}
}
The function code of page life cycle is as follows
/* * It can be done by $page Gets or modifies the of the current page Variable state handler lifecyle Etc * It can be done by app Get or modify the global application Variable state Etc * The details can be console.info In the editor Console Panel for more information * if necessary async-await, Please before the method async */
export default {
onPageLoad(query) {
//console.log('---------> LifeCycle onPageLoad', query)
},
onPageShow() {
//console.log('---------> LifeCycle onPageShow')
},
onPageReady() {
//console.log('---------> LifeCycle onPageReady')
},
onPageHide() {
//console.log('---------> LifeCycle onPageHide')
},
onPageUnload() {
//console.log('---------> LifeCycle onPageUnload')
},
}
Introduction to customized methods
When setting events for components , In addition to using the platform method , You can also create custom methods . The customization method is at the bottom of the page handler Create in
Click on + You need to enter the name of the custom method after the number
The custom method created is as follows :
/** * * It can be done by $page Gets or modifies the of the current page Variable state handler lifecyle Etc * It can be done by app Get or modify the global application Variable state Etc * The details can be console.info In the editor Console Panel for more information * Be careful : This method is only valid on the page to which it belongs * if necessary async-await, Please amend it to export default async function() {} **/
/** * @param {Object} event - Event object . * @param {string} event.name - Event name . * @param {string} event.target - The target node of the event ( The node that triggered the event ). * @param {string} event.currentTarget - The node currently processing this event . Including bubbling and capture events .. * * @param {Object} data * @param {any} data.target - Get the data of event parameters **/
export default function({
event, data}) {
}
If you want to understand the logic of custom methods, you need to learn es6 Basic grammar of , I still recommend rookie tutorial . In addition to mastering basic knowledge , We also need to learn how to debug the code . commonly js The code can be used console.log To output variables , For example, we want to see event and data What on earth is , Then we can output in the code , The code is as follows :
/** * * It can be done by $page Gets or modifies the of the current page Variable state handler lifecyle Etc * It can be done by app Get or modify the global application Variable state Etc * The details can be console.info In the editor Console Panel for more information * Be careful : This method is only valid on the page to which it belongs * if necessary async-await, Please amend it to export default async function() {} **/
/** * @param {Object} event - Event object . * @param {string} event.name - Event name . * @param {string} event.target - The target node of the event ( The node that triggered the event ). * @param {string} event.currentTarget - The node currently processing this event . Including bubbling and capture events .. * * @param {Object} data * @param {any} data.target - Get the data of event parameters **/
export default function({
event, data}) {
console.log(event,data)
}
How to make the custom method effective , We can select the button component , Click Add behavior at the bottom of the property tab
Select the custom method in the pop-up window , Choose the custom method we just set
Then click in the editor console window
Click the button to see that the two variables just output are printed into the console
Different components have different contents here , Especially when we are programming, we need to get the value in the component , Both of these objects are useful .
Well, this section introduces the use of life cycle functions and custom methods in low code , Only understand the concept thoroughly , Only in your actual business development can you be handy .
边栏推荐
- Differential GPS RTK thousand search
- MySQL master-slave replication
- Python book learning notes - Chapter 09 section 01 create and use classes
- Prime Protocol宣布在Moonbeam上的跨链互连应用程序
- Ybtoj coloring plan [tree chain dissection, segment tree, tarjan]
- Cf464e the classic problem [shortest path, chairman tree]
- KS003基于JSP和Servlet实现的商城系统
- Global and Chinese markets for patent hole oval devices 2022-2028: Research Report on technology, participants, trends, market size and share
- How many of the 10 most common examples of istio traffic management do you know?
- Facebook and other large companies have leaked more than one billion user data, and it is time to pay attention to did
猜你喜欢
在字节做测试5年,7月无情被辞,想给划水的兄弟提个醒
Basic knowledge of binary tree, BFC, DFS
MySql数据库root账户无法远程登陆解决办法
WPF effect Article 191 box selection listbox
10 exemples les plus courants de gestion du trafic istio, que savez - vous?
C#(二十九)之C#listBox checkedlistbox imagelist
mysql关于自增长增长问题
Error 1045 (28000): access denied for user 'root' @ 'localhost' (using password: no/yes
[disassembly] a visual air fryer. By the way, analyze the internal circuit
[FPGA tutorial case 11] design and implementation of divider based on vivado core
随机推荐
Do you know cookies, sessions, tokens?
IDEA编译JSP页面生成的class文件路径
关于进程、线程、协程、同步、异步、阻塞、非阻塞、并发、并行、串行的理解
/usr/bin/gzip: 1: ELF: not found/usr/bin/gzip: 3: : not found/usr/bin/gzip: 4: Syntax error:
How many of the 10 most common examples of istio traffic management do you know?
Yyds dry goods inventory web components series (VII) -- life cycle of custom components
cookie,session,Token 这些你都知道吗?
Record the pit of NETCORE's memory surge
Viewing and verifying backup sets using dmrman
Tips for using dm8huge table
Global and Chinese markets for fire resistant conveyor belts 2022-2028: Research Report on technology, participants, trends, market size and share
Le compte racine de la base de données MySQL ne peut pas se connecter à distance à la solution
C#(二十七)之C#窗体应用
使用JS完成一个LRU缓存
[disassembly] a visual air fryer. By the way, analyze the internal circuit
STC8H开发(十二): I2C驱动AT24C08,AT24C32系列EEPROM存储
Ethernet port &arm & MOS &push-pull open drain &up and down &high and low sides &time domain and frequency domain Fourier
WPF效果第一百九十一篇之框选ListBox
[adjustable delay network] development of FPGA based adjustable delay network system Verilog
绑定在游戏对象上的脚本的执行顺序