当前位置:网站首页>Wechat applet comprehensive case practice 1
Wechat applet comprehensive case practice 1
2022-07-22 21:26:00 【Cute and strange】
1. The user login
Purpose :
In order to improve efficiency UI beautify , It mainly simulates the data transmission of user login , Suitable for beginners .
Realization function :
- Get into " User center " The page needs Determine whether the user is logged in
- If the user is not logged in , be Jump to login page
- On the login page Get user name information
- If the user is already logged in , Need to be in “ User center ” page Show login user name
Knowledge point :
- Configuration page (page,window,tabBar)
- Life cycle ( stay onLoad Judge whether the user exists )
- Event binding ( The login button 、input Input box )
- Data acquisition and transmission ( difficulty )
First step : Prepare the basic page (index user login).wxml
//login.wxml
<text> user name </text>
<input bindinput='usernameInput'></input>
<text> password </text>
<input password='true'></input>
<button bindtap='btnLogin'> Sign in </button>
//user.wxml
<text>hello!{
{username}}</text>
//index.wxml
<view>
<image src='/image/index.jpg' class='myclass'></image>
</view>
<view>
<image src='/image/index.jpg' class='myclass'></image>
</view>
The second step : Configuration page ----- add to tabBar, Add data userinfo
( Key code )
//app.json{
"tabBar": {
"color": "#333",
"list": [
{
"pagePath": "pages/index/index",
"text": " home page "
},
{
"pagePath": "pages/user/user",
"text": " User center "
}
]
}
}
//app.js
App({
// Store user information
appData:{
userinfo:null
}
})
The third step : complete user.js Part of the logic of , When userinfo Jump to login page
//user.js
onLoad: function (options) {
if(app.appData.userinfo==null){
console.log("username is null"),
wx.redirectTo({
url: '../login/login'
})
}
}
Step four : complete login.js Logic , by input and button Bind click event
var app = getApp()
// Get input
usernameInput:function(event){
this.setData({username:event.detail.value})
},
// Click event of login button , to appInfo assignment
btnLogin:function(){
app.appData.userinfo={username:this.data.username},
wx.switchTab({url: '../user/user'})
}
Step five : complete user.js The remaining logic of , When userinfo Display when it is not empty
onLoad: function (options) {
if(app.appData.userinfo==null){
console.log("username is null"),
wx.redirectTo({
url: '../login/login'
})
}else{
this.setData({username:app.appData.userinfo.username})
}
}
Achievement examples :
边栏推荐
- 人类群星网站收集计划--Michael Kerrisk
- 解决TraceCompass网站打不开和Stackoverflow显示不全的问题
- [LTTng学习之旅]------Components of LTTng 解构
- YOLO9000: Better, Faster, Stronger
- Wechat applet cannot read property'setdata'of null error
- 3.远程连接和SSH
- Significance learning record of FFT in MATLAB
- Buuctf breakthrough diary 04 -- [strong net cup 2019] casual note 1
- Chapter 2: configure data sources, redis, security, swagger and other tools jar for the project
- 3. Remote connection and SSH
猜你喜欢
物理层2.1
Using MySQL database in Django
使用js写个3d banner
[lttng learning journey] ----- components of lttng deconstruction
云报传媒广场数字电视转模拟系统设计分享
[LTTng学习之旅]------Trace View初探
matlab中 FFT 的意义 学习记录
Network Accounting - layered structure, OSI communication process, tcp/ip model and 5-layer reference model
Buuctf breakthrough diary 02-- [hctf 2018] warmup1
浅谈 filter伪协议的特性
随机推荐
8. Memory and disk management
Nssctf-01-[swpuctf 2021 freshman competition]gift_ F12
Buuctf breakthrough diary -- [geek challenge 2019] hardsql1
next中的样式写法
BUUCTF闯关日记03--[极客大挑战 2019]Havefun1
使用vis-network根据节点坐标定位环形工具栏
1.虚拟化和容器技术
Leetcode notes (I) backtracking
RPM包管理—YUM在线管理--YUM命令
流程控制—if语句
链表中的双指针——快慢指针
JUC-7.1-线程协作-Semaphore
使用js写个3d banner
JVM principle and performance tuning
LeetCode笔记(一)回溯
(六)vulhub专栏:Apereo-cas 4.x反序列化漏洞
BUUCTF闯关日记--[MRCTF2020]你传你呢(超详解)
Buuctf breakthrough diary 03 -- [geek challenge 2019] havefun1
Bash basic functions alias and shortcut keys
(6) Vulhub column: apereo CAS 4.x deserialization vulnerability