请求响应错误统一处理

This commit is contained in:
sfmind
2022-04-21 01:46:45 +08:00
parent 713817d0f1
commit e9c0c452c8
7 changed files with 38 additions and 57 deletions

View File

@ -121,7 +121,6 @@ export default {
.then(res => {
uni.$u.toast('点击了重置密码')
})
.catch(err => {})
},
navigateBack() {
uni.navigateBack()

View File

@ -174,22 +174,14 @@ export default {
},
methods: {
loadBannerData() {
getBannerData()
.then(res => {
this.bannerList = res.data
})
.catch(err => {
//console.log(err)
})
getBannerData().then(res => {
this.bannerList = res.data
})
},
loadNoticeData() {
getNoticeData()
.then(res => {
this.noticeList = res.data
})
.catch(err => {
//console.log(err)
})
getNoticeData().then(res => {
this.noticeList = res.data
})
},
handleSearchClick(e) {
uni.$u.route('/pages/search/search')
@ -331,7 +323,6 @@ export default {
}
.prod-list {
.prod-item {
background: #ffffff;
@include flex-space-between;

View File

@ -129,22 +129,13 @@ export default {
})
//scene:1登陆获取验证码场景
sendSmsCode({ mobile: mobile, scene: 1 })
.then(res => {
//console.log(res)
uni.hideLoading()
if (res.code === 0) {
// 这里此提示会被this.start()方法中的提示覆盖
uni.$u.toast('验证码已发送')
// 通知验证码组件内部开始倒计时
this.$refs.uCode.start()
} else {
uni.$u.toast(res.msg)
}
})
.catch(err => {
uni.$u.toast('服务器接口请求异常')
})
sendSmsCode({ mobile: mobile, scene: 1 }).then(res => {
//console.log(res)
uni.hideLoading()
uni.$u.toast('验证码已发送')
// 通知验证码组件内部开始倒计时
this.$refs.uCode.start()
})
} else {
uni.$u.toast('倒计时结束后再发送')
}
@ -159,21 +150,13 @@ export default {
})
},
handleLoginPromise(promise) {
promise
.then(res => {
if (res.code === 0) {
this.$store.commit('setToken', res.data)
uni.$u.toast('登录成功')
setTimeout(() => {
this.navigateBack()
}, 1000)
} else {
uni.$u.toast(res.msg)
}
})
.catch(err => {
uni.$u.toast('接口请求失败')
})
promise.then(res => {
this.$store.commit('setToken', res.data)
uni.$u.toast('登录成功')
setTimeout(() => {
this.navigateBack()
}, 1000)
})
},
navigateBack() {
uni.navigateBack()

View File

@ -78,12 +78,9 @@ export default {
})
},
handleSubmit() {
this.$refs.form
.validate()
.then(res => {
uni.$u.toast('点击了注册账号')
})
.catch(err => {})
this.$refs.form.validate().then(res => {
uni.$u.toast('点击了注册账号')
})
},
navigateBack() {
uni.navigateBack()

View File

@ -72,7 +72,9 @@ export default {
}
},
onLoad() {
this.$store.dispatch('obtainUserInfo')
if (this.hasLogin){
this.$store.dispatch('obtainUserInfo')
}
},
methods: {
loginOrJump(pageUrl) {