利用quickstart工程,實現用戶登錄過程,并簡單校驗用戶名和密碼是否正確。
1.底部有兩個tabBar(首頁/個人中心)
2.個人中心顯示用戶信息。
首次切換到個人中心,需要先登錄,才能看到個人信息。登錄后,就一直顯示用戶信息。
改app.json文件,添加tabBar
app.json { "pages":[ "pages/index/index", "pages/user/user", "pages/login/login" ], "window":{ "backgroundTextStyle":"light", "navigationBarBackgroundColor": "#fff", "navigationBarTitleText": "WeChat", "navigationBarTextStyle":"black" }, "tabBar": { "list": [{ "pagePath": "pages/index/index", "text": "首頁" },{ "pagePath": "pages/user/user", "text": "個人中心" }] } } |
添加用戶登錄頁面login 兩個輸入框(用戶名和密碼) 一個按鈕 當點擊按鈕時,驗證用戶名和密碼是否正確,如果正確,則跳轉到用戶頁面(用戶的個人信息)。 否則在登錄頁面有個錯誤提示"請輸入正確的用戶名和密碼"。
login.wxml
<view class="mcontainer"> <view class="item"> <view class="login-item"> <view class="login-item-info">用戶名</view> <view><input /></view> </view> <view class="login-item"> <view class="login-item-info">密碼</view> <view class="login-pwd"> <input style="flex-grow:1" password="true" /> <text> 忘記密碼 </text> </view> </view> <view class="login-item bottom"> <button class="login-btn" >登錄</button> </view> <view class="login-item bottom"> <text> 用戶名或密碼錯誤 </text> </view> </view> </view> |
login.wxss
.mcontainer { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: space-between; } .item{ flex-grow:1; height: 30%; overflow: hidden; display: flex; justify-content: center; align-items: center; flex-direction: column; width: 96%; padding: 0 2%; } .login-item{ width: 90%; margin-top: 30rpx; border-bottom: 1px solid #eee; flex-grow:1; display: flex; flex-direction: column; justify-content: flex-end; padding-bottom: 20rpx; } .bottom{ border-bottom: 0px; } .login-item-info{ font-size: 8px; color: #888; padding-bottom: 20rpx; } .login-pwd{ display: flex; justify-content: space-between; flex-grow: 1; align-items: center; } .login-pwd text{ height: 100%; font-size: 14px; color: #888; display: flex; } .login-btn{ width: 80%; color: white; background-color: green; border-radius: 0; font-size: 14px; } .login-btn:hover{ width: 80%; color: white; border-radius: 0; } |
綁定bindinput事件