async yes() {
const res = await this.$myrequest({
url: '/mcenter/member/withdrawal',
method: 'POST',
data: {
identity: this.zhanghao,
name: this.name,
money: this.qian,
},
header: {
'content-type': 'application/x-www-form-urlencoded' //自定义请求头信息
},
})
if (res.data.code == 1) {
uni.showToast({
title: res.data.msg,
icon: "success",
duration: 2000
})
location.reload()
} else if (res.data.code == -1) {
uni.showToast({
title: "即将跳转登录",
icon: "error",
duration: 2000
})
let url = encodeURIComponent(
"https://www.zhilongyihuo.com/html/qiye/#/pages/contact/contact?shop_id=" + this.shopid)
window.location.href =
"https://www.zhilongyihuo.com/index.php?s=/mobile/passport/login.html&redirecturl=" + url
} else {
return uni.showToast({
title: res.data.msg,
icon: "error",
duration: 2000
})
window.location.href = "https://www.zhilongyihuo.com/html/qiye/#/pages/cart/cart"
}
}
this.$myrequest为封装的文件内容为
const base_url = "https://www.zhilongyihuo.com/index.php"
export const myrequest = (options) => {
return new Promise((resolve, reject) => {
uni.request({
url: base_url + options.url,
method: options.method || 'GET',
data: options.data || {},
header: options.header || {},
success: (res) => {
// console.log(res)
// if (res.data.code == -1) {
// uni.showToast({
// title: "即将跳转登录",
// icon: "error",
// duration: 2000
// })
// window.location.href =
// "https://www.zhilongyihuo.com/index.php?s=/mobile/passport/login.html"
// }
resolve(res)
},
fail: (err) => {
uni.showToast({
title: "请求接口失败",
icon: "error"
})
reject(err)
}
})
})
}
// myrequest({
// url:'/api/getinfo',
// method:'POST',
// data:{}
// })
在main.js里引入
import {myrequest} from './until/api.js'
Vue.prototype.$myrequest = myrequest



本文介绍了使用async/await实现的会员提现功能,通过axios封装的myrequest进行POST请求。遇到登录验证会跳转,成功或失败都有明确提示。
1596

被折叠的 条评论
为什么被折叠?



