是post的
这是我的项目 是json的 一直在报异常
这是另一个项目里正确的 使用from data 才可以接收
这是我的api
1.我需要怎么改 才能请求成功
网上说这样设置 但是我加上 也不行
body: qs.stringify(data), // 或者将data转换为formData格式
hhttps://img-mid.csdnimg.cn/release/static/image/mid/ask/092841217646158.png "#left")
eaders: new Headers({
'Content-Type': 'application/x-www-form-urlencoded' // 不进行header设置的默认格式
})
request方法怎么封装的?用的axios还是什么?原生的wx.request不是这样配置的
原生写法,不支持Promise
wx.request({
url: '/api/goods/detail',
method:'POST',
header:{'content-type':'application/x-www-form-urlencoded'},
data:{id:id},
success:(res){
console.log(res)
},faill(){
console.log('error')
}
})
axios
import qs from 'qs';
const data = { 'id': id};
const options = {
method: 'POST',
headers: { 'content-type': 'application/x-www-form-urlencoded' },
data: qs.stringify(data),
url:'/api/goods/detail',
};
axios(options);
您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!