溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

「小程序JAVA實戰」小程序 loading 提示框與頁面跳

發布時間:2020-08-10 17:49:05 來源:網絡 閱讀:469 作者:IT人故事 欄目:移動開發

登錄注冊都完成了,有可能會遇到一些問題,服務器繁忙的話,后臺接口卡主了,也沒任何提示,小程序端的用戶比較暴力一直惦記怎么辦。

加載提示框,隱藏加載中提示框,頁面跳轉

https://developers.weixin.qq.com/miniprogram/dev/api/api-react.html#wxshowtoastobject
https://developers.weixin.qq.com/miniprogram/dev/api/api-react.html#wxhideloading

「小程序JAVA實戰」小程序 loading 提示框與頁面跳

「小程序JAVA實戰」小程序 loading 提示框與頁面跳

跳轉實例

  • 用戶登錄


  • 用戶注冊

const?app?=?getApp()

Page({
??data:?{

??},

??doLogin:?function?(e)?{
????var?formObject?=?e.detail.value;
????var?username?=?formObject.username;
????var?password?=?formObject.password;

????//?簡單驗證
????if?(username.length?==?0?||?password.length?==?0)?{
??????wx.showToast({
????????title:?'用戶名或密碼不能為空',
????????icon:?'none',
????????duration:?3000
??????})
????}?else?{
??????wx.showLoading({
????????title:?'正在加載中。。。'
??????});
??????wx.request({
????????url:?app.serverUrl?+?"/login",
????????method:?"POST",
????????data:?{
??????????username:?username,
??????????password:?password
????????},
????????header:?{
??????????'content-type':?'application/json'?//?默認值
????????},
????????success:?function?(res)?{
??????????console.log(res.data);
??????????var?status?=?res.data.status;
??????????wx.hideLoading();
??????????if?(status?==?200)?{
????????????wx.showToast({
??????????????title:?"用戶登陸成功~!",
??????????????icon:?'none',
??????????????duration:?3000
????????????})
????????????app.userinfo?=?res.data.data;
??????????}?else?if?(status?==?500)?{
????????????wx.showToast({
??????????????title:?res.data.msg,
??????????????icon:?'none',
??????????????duration:?3000
????????????})
??????????}
????????}
??????})
????}
??},
??goLoginPage:?function?(e)?{
????console.log("跳轉到注冊");
??}
})

「小程序JAVA實戰」小程序 loading 提示框與頁面跳

  • 用戶注冊

const?app?=?getApp()

Page({
????data:?{

????},

????doRegist:?function(e)?{
??????var?formObject?=?e.detail.value;
??????var?username?=?formObject.username;
??????var?password?=?formObject.password;

??????//?簡單驗證
??????if?(username.length?==?0?||?password.length?==?0)?{
????????wx.showToast({
??????????title:?'用戶名或密碼不能為空',
??????????icon:?'none',
??????????duration:?3000
????????})
??????}else{
????????wx.showLoading({
??????????title:?'正在加載中。。。'
????????});
????????wx.request({
??????????url:?app.serverUrl?+"/regist",?
??????????method:"POST",
??????????data:?{
????????????username:?username,
????????????password:?password
??????????},
??????????header:?{
????????????'content-type':?'application/json'?//?默認值
??????????},
??????????success:?function?(res)?{
????????????console.log(res.data);
????????????var?status?=?res.data.status;
????????????wx.hideLoading();
????????????if(status?==?200){
??????????????wx.showToast({
????????????????title:?"用戶注冊成功~!",
????????????????icon:?'none',
????????????????duration:?3000
??????????????})
??????????????app.userinfo?=?res.data.data;
????????????}else?if(status?==?500){
??????????????wx.showToast({
????????????????title:?res.data.msg,
????????????????icon:?'none',
????????????????duration:?3000
??????????????})
????????????}
??????????}
????????})
??????}
????},
????goLoginPage:function(e){
??????console.log("跳轉到登錄");
????}
})

「小程序JAVA實戰」小程序 loading 提示框與頁面跳

  • 用戶登錄跳轉

const?app?=?getApp()

Page({
??data:?{

??},

??doLogin:?function?(e)?{
????var?formObject?=?e.detail.value;
????var?username?=?formObject.username;
????var?password?=?formObject.password;

????//?簡單驗證
????if?(username.length?==?0?||?password.length?==?0)?{
??????wx.showToast({
????????title:?'用戶名或密碼不能為空',
????????icon:?'none',
????????duration:?3000
??????})
????}?else?{
??????wx.showLoading({
????????title:?'正在加載中。。。'
??????});
??????wx.request({
????????url:?app.serverUrl?+?"/login",
????????method:?"POST",
????????data:?{
??????????username:?username,
??????????password:?password
????????},
????????header:?{
??????????'content-type':?'application/json'?//?默認值
????????},
????????success:?function?(res)?{
??????????console.log(res.data);
??????????var?status?=?res.data.status;
??????????wx.hideLoading();
??????????if?(status?==?200)?{
????????????wx.showToast({
??????????????title:?"用戶登陸成功~!",
??????????????icon:?'none',
??????????????duration:?3000
????????????})
????????????app.userinfo?=?res.data.data;
??????????}?else?if?(status?==?500)?{
????????????wx.showToast({
??????????????title:?res.data.msg,
??????????????icon:?'none',
??????????????duration:?3000
????????????})
??????????}
????????}
??????})
????}
??},
??goRegisterPage:?function?(e)?{
????wx.redirectTo({
??????url:?'../userRegister/userRegister',
????})
??}
})

「小程序JAVA實戰」小程序 loading 提示框與頁面跳

  • 用戶注冊跳轉
    userRegister.js

const?app?=?getApp()

Page({
????data:?{

????},

????doRegist:?function(e)?{
??????var?formObject?=?e.detail.value;
??????var?username?=?formObject.username;
??????var?password?=?formObject.password;

??????//?簡單驗證
??????if?(username.length?==?0?||?password.length?==?0)?{
????????wx.showToast({
??????????title:?'用戶名或密碼不能為空',
??????????icon:?'none',
??????????duration:?3000
????????})
??????}else{
????????wx.showLoading({
??????????title:?'正在加載中。。。'
????????});
????????wx.request({
??????????url:?app.serverUrl?+"/regist",?
??????????method:"POST",
??????????data:?{
????????????username:?username,
????????????password:?password
??????????},
??????????header:?{
????????????'content-type':?'application/json'?//?默認值
??????????},
??????????success:?function?(res)?{
????????????console.log(res.data);
????????????var?status?=?res.data.status;
????????????wx.hideLoading();
????????????if(status?==?200){
??????????????wx.showToast({
????????????????title:?"用戶注冊成功~!",
????????????????icon:?'none',
????????????????duration:?3000
??????????????})
??????????????app.userinfo?=?res.data.data;
????????????}else?if(status?==?500){
??????????????wx.showToast({
????????????????title:?res.data.msg,
????????????????icon:?'none',
????????????????duration:?3000
??????????????})
????????????}
??????????}
????????})
??????}
????},
????goLoginPage:function(e){
??????wx.redirectTo({
????????url:?'../userLogin/userLogin',
??????})
????}
})

「小程序JAVA實戰」小程序 loading 提示框與頁面跳

PS:這次就是我們的跳轉和loading的介紹。


向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女