哪位大锅帮忙看一下呗
封装的请求:
export const request = (option) => {
option.url = 'http://localhost:3000/api' + option.url
option.method = option.method || "Get"
option.data = option.data || {}
option.header = option.header || {"content-type":"application/json"}
option.dataType = option.dataType || "json"
return new Promise((res,rej) => {
uni.showLoading({
title: '数据加载中'
})
uni.request({
...option,
success:(val) => {
if(val.code != 200) {
return rej()
}
const data = val
res(data)
}
})
uni.hideLoading()
})
}
发请求的事件:
methods: {
async login (){
try {
let form = this.form
let newForm = Object.assign({},form)
console.log('newForm',newForm);
let get = await request({url:`/login/get/accnum/${newForm.username}/${newForm.userpwd}`,method:'get'})
console.log('get',get);
// let post = await request({url:'/login/post/accnum',method:'post',data:newForm})
// console.log('post---------',post);
} catch(err) {
console.log(err);
}
}
},
我用postman试过这个请求是没问题的,但是不知道为什么我使用async await成这样了