微信小程序?qū)崿F(xiàn)登錄界面
微信小程序的登錄界面實(shí)現(xiàn),供大家參考,具體內(nèi)容如下
<view class="container">
<view class="wrapper">
<view class="left-top-sign">LOGIN</view>
<view class="welcome">
歡迎回來!
</view>
<view class="input-content">
<view class="input-item">
<text class="tit">手機(jī)號(hào)碼</text>
<input type="text" placeholder="請(qǐng)輸入手機(jī)號(hào)碼" id='phone' data-type='phone' bindinput='handerInput' />
</view>
<view class="input-item">
<text class="tit">密碼</text>
<input type="password" placeholder="請(qǐng)輸入密碼" id='password' data-type='password' bindinput='handerInput' />
</view>
</view>
<button class="confirm-btn">登錄</button>
<view class="forget-section">
忘記密碼?
</view>
</view>
<view class="register-section">
還沒有賬號(hào)?
<text>馬上注冊(cè)</text>
</view>
</view>
最基本的表單提交。
data: {
phone: '', //手機(jī)號(hào)
password: '' //密碼
},
/**
* 生命周期函數(shù)--監(jiān)聽頁面加載
*/
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
})
},
/**
雙向綁定的實(shí)現(xiàn),利用bindinput 事件,可用id或者dataset 唯一確定數(shù)據(jù)。
id可傳入一個(gè)數(shù)據(jù),dataset可傳入多個(gè)數(shù)據(jù)。
微信小程序的交互:消息顯示框。(官方鏈接)
對(duì)于登錄按鈕綁定一個(gè)點(diǎn)擊回調(diào)函數(shù)。
//html
<button class="confirm-btn" bindtap="login">登錄</button>
//js
login() {
let { phone, password } = this.data;
console.log(password);
/**
* 手機(jī)號(hào)驗(yàn)證
* 手機(jī)號(hào)為空
* 手機(jī)號(hào)式錯(cuò)誤
* 手機(jī)號(hào)正確
*/
if (!phone) {
wx.showToast({
title: '手機(jī)號(hào)不能為空',
icon: 'none'
})
return;
}
//定義手機(jī)號(hào)的正則表達(dá)式
let phoneReg = /^1(3|4|5|6|7|8|9)\d{9}$/
if (!phoneReg.test(phone)) {
wx.showToast({
title: '手機(jī)號(hào)格式錯(cuò)誤',
icon: 'none'
})
return;
}
if (!password) {
wx.showToast({
title: '密碼不能為空',
icon: 'none'
})
return;
}
wx.showToast({
title: '前端驗(yàn)證通過'
})
后端驗(yàn)證,調(diào)用接口,通過響應(yīng)的狀態(tài)碼來返回給用戶登錄的信息。
let result = await request('/login/cellphone', { phone, password });
if (result.code === 200) {
wx.showToast({
title: '登陸成功',
})
}
else if (result.code === 400) {
wx.showToast({
title: '手機(jī)號(hào)錯(cuò)誤',
icon: 'none'
})
}
else if (result.code === 502) {
wx.showToast({
title: '密碼錯(cuò)誤',
icon: 'none'
})
}
else {
wx.showToast({
title: '登錄失敗,請(qǐng)重新登錄',
icon: 'none'
})
}
},
個(gè)人中心點(diǎn)擊頭像,跳轉(zhuǎn)登錄界面,登錄成功后將用戶個(gè)人信息數(shù)據(jù)緩存(使用setStorageSync,和getStorageSync 方法),然后使用switchTab 跳轉(zhuǎn)到tabbar下的個(gè)人中心頁,然后將獲得的緩存數(shù)據(jù)儲(chǔ)存到j(luò)s的data中,注意json格式的轉(zhuǎn)化,最后在
html里三元運(yùn)算特判一下。
<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: '游客'}}</text>
</view>
</view>
//login.js
if (result.code === 200) {
wx.showToast({
title: '登陸成功',
})
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)
})
}
},

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 微信小程序登錄與注冊(cè)功能的實(shí)現(xiàn)詳解
- 微信小程序?qū)崿F(xiàn)登錄注冊(cè)功能
- 詳解微信小程序入門從這里出發(fā)(登錄注冊(cè)、開發(fā)工具、文件及結(jié)構(gòu)介紹)
- 微信小程序?qū)崿F(xiàn)注冊(cè)登錄功能(表單校驗(yàn)、錯(cuò)誤提示)
- 微信小程序+云開發(fā)實(shí)現(xiàn)歡迎登錄注冊(cè)
- 微信小程序登錄態(tài)和檢驗(yàn)注冊(cè)過沒的app.js寫法
- 微信小程序?qū)崿F(xiàn)登錄注冊(cè)tab切換效果
- 微信小程序?qū)崿F(xiàn)登錄界面示例
- 微信小程序?qū)崿F(xiàn)登錄注冊(cè)界面
相關(guān)文章
使用axios實(shí)現(xiàn)上傳圖片進(jìn)度條功能
Axios 是一個(gè)基于 promise 的 HTTP 庫,可以用在瀏覽器和 node.js 中。這篇文章主要介紹了使用axios實(shí)現(xiàn)上傳圖片進(jìn)度條,需要的朋友可以參考下2017-12-12
JS實(shí)現(xiàn)彩色圖片轉(zhuǎn)換為黑白圖片的3種方法
本文主要介紹了JS實(shí)現(xiàn)彩色圖片轉(zhuǎn)換為黑白圖片的3種方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2024-09-09
JS/jQuery實(shí)現(xiàn)獲取時(shí)間的方法及常用類完整示例
這篇文章主要介紹了JS/jQuery實(shí)現(xiàn)獲取時(shí)間的方法及常用類,結(jié)合完整實(shí)例形式分析了javascript針對(duì)日期時(shí)間的獲取、轉(zhuǎn)換、計(jì)算與檢測(cè)相關(guān)操作技巧,需要的朋友可以參考下2019-03-03
如何基于uni-app實(shí)現(xiàn)微信小程序一鍵登錄與退出登錄功能
uni-app 是使用vue的語法+小程序的標(biāo)簽和API的一套框架,是一套代碼多端使用,目前是大前端的一種趨勢(shì),下面這篇文章主要給大家介紹了關(guān)于如何基于uni-app實(shí)現(xiàn)微信小程序一鍵登錄與退出登錄功能的相關(guān)資料,需要的朋友可以參考下2022-09-09
JS實(shí)現(xiàn)的用來對(duì)比兩個(gè)用指定分隔符分割的字符串是否相同
這篇文章主要介紹了JS實(shí)現(xiàn)的用來對(duì)比兩個(gè)用指定分隔符分割的字符串是否相同,本文代碼為特殊需要而寫,需要的朋友可以參考下2014-09-09
JavaScript高級(jí)程序設(shè)計(jì) 讀書筆記之九 本地對(duì)象Array
本地對(duì)象Array,數(shù)組等操作函數(shù)2012-02-02
js+html5實(shí)現(xiàn)canvas繪制圓形圖案的方法
這篇文章主要介紹了js+html5實(shí)現(xiàn)canvas繪制圓形圖案的方法,涉及html5圖形繪制的基礎(chǔ)技巧,需要的朋友可以參考下2015-06-06

