react native 请求注意事项
发布时间:2020-12-15 20:38:45 所属栏目:百科 来源:网络整理
导读:请求地址一定得为域名形式,不能是ip 错误请求:axios.get('127.0.0.1:3000/test').then(res={}).catch(err={})//会进入catch里面正确请求:axios.get('http://asd.tunnel.qydev.com/test').then(res={}).catch(err={})//请求成功 axios.get请求 axios.get('
请求地址一定得为域名形式,不能是ip错误请求:axios.get('127.0.0.1:3000/test').then(res=>{}).catch(err=>{})//会进入catch里面 正确请求:axios.get('http://asd.tunnel.qydev.com/test').then(res=>{}).catch(err=>{})//请求成功 axios.get请求axios.get('http://asd.tunnel.qydev.com/test',{ params:{ username: 'xxx',pass: 'xxx' } }) .then(res => { console.log('res:',res) }) .catch(err => { console.log('err:',err) }) axios.post请求axios.post('/user',{ firstName: 'Fred',lastName: 'Flintstone' }) .then(function (response) { console.log(response); }) .catch(function (error) { console.log(error); }); async await写法async getData(){ // let data = await axios.get('http://asd.tunnel.qydev.com/test') let data = await axios.post('http://asd.tunnel.qydev.com/login',{name:'123',pass:'123'}) console.log('data:',data) } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |