The login interface of WeChat applet is implemented for your reference. The specific content is as follows <view class="container"> <view class="wrapper"> <view class="left-top-sign">LOGIN</view> <view class="welcome"> Welcome back! </view> <view class="input-content"> <view class="input-item"> <text class="tit">Mobile phone number</text> <input type="text" placeholder="Please enter your phone number" id='phone' data-type='phone' bindinput='handerInput' /> </view> <view class="input-item"> <text class="tit">Password</text> <input type="password" placeholder="Please enter your password" id='password' data-type='password' bindinput='handerInput' /> </view> </view> <button class="confirm-btn">Login</button> <view class="forget-section"> forget the password? </view> </view> <view class="register-section"> No account yet? <text>Register now</text> </view> </view> The most basic form submission. data: { phone: '', //phone number password: '' //password}, /** * Life cycle function--listen for page loading*/ onLoad: function (options) { }, handerInput(event) { //let type = event.currentTarget.dataset.type; let type = event.currentTarget.id; console.log(event); this.setData({ [type]: event.detail.value }) }, /** To implement two-way binding, use the bindinput event and use id or dataset to uniquely identify data. One data can be passed into id, and multiple data can be passed into dataset. WeChat applet interaction: message display box. (Official Link) Bind a click callback function to the login button. //html <button class="confirm-btn" bindtap="login">Login</button> //js login() { let { phone, password } = this.data; console.log(password); /** * Phone number verification* Phone number is empty* Phone number format is wrong* Phone number is correct*/ if (!phone) { wx.showToast({ title: 'Mobile number cannot be empty', icon: 'none' }) return; } //Define the regular expression for the phone number let phoneReg = /^1(3|4|5|6|7|8|9)\d{9}$/ if (!phoneReg.test(phone)) { wx.showToast({ title: 'The format of the mobile phone number is wrong', icon: 'none' }) return; } if (!password) { wx.showToast({ title: 'The password cannot be empty', icon: 'none' }) return; } wx.showToast({ Title: 'Front-end verification passed' }) Backend verification, calling the interface, and returning the login information to the user through the response status code. let result = await request('/login/cellphone', { phone, password }); if (result.code === 200) { wx.showToast({ title: 'Login successful', }) } else if (result.code === 400) { wx.showToast({ title: 'Wrong phone number', icon: 'none' }) } else if (result.code === 502) { wx.showToast({ title: 'Wrong password', icon: 'none' }) } else { wx.showToast({ title: 'Login failed, please log in again', icon: 'none' }) } }, Click the avatar in the personal center to jump to the login interface. After successful login, cache the user's personal information data (using setStorageSync and getStorageSync methods), then use switchTab to jump to the personal center page under the tabbar, and then store the obtained cached data in js data. Pay attention to the conversion of json format, and finally Special judgment on ternary operation in html. <view class="user-info-box" bindtap='toLogin'> <view class="portrait-box"> <image class="portrait" src='{{userInfo.avatarUrl?userInfo.avatarUrl:"/static/images/personal/missing-face.png"}}'></image> </view> <view class="info-box"> <text class="username">{{userInfo.nickname?userInfo.nickname: 'Visitor'}}</text> </view> </view> //login.js if (result.code === 200) { wx.showToast({ title: 'Login successful', }) wx.setStorageSync('userInfo', JSON.stringify(result.profile)); wx.switchTab({ url: '/pages/personal/personal' }) } // personal.js onLoad: function (options) { let userInfo = wx.getStorageSync('userInfo'); if (userInfo) { this.setData({ userInfo: JSON.parse(userInfo) }) } }, The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Detailed explanation of the usage of DECIMAL in MySQL data type
>>: VMware Workstation installation Linux (Ubuntu) system
Preface: Recently, I encountered a management sys...
Table of contents 1. Literals 1.1 Numeric literal...
It is a very common requirement to set the horizo...
In the vertical direction, you can set the row al...
Table of contents Basic Edition Step 1: Configure...
Port Mapping Before the Docker container is start...
Vim is a powerful full-screen text editor and the...
For example, there is an input box <el-input r...
Table of contents How to view the source code of ...
Preface One day, I was suddenly asked about MySQL...
Preface: The previous article described several c...
This article example shares the specific code for...
Index extension: InnoDB automatically extends eac...
Today, I fell into the trap again. I have encount...
When we create a page, especially a homepage, we ...