axios的get,post方法
学习vue和nodejs的过程当中,涉及到了axios,今天为了测试,写了get和post两个方法来跟node服务端交互,结果因为header和参数弄了好久,在此记录一下,同时分享;
由于刚接触axios,在测试方法中,写的都是很简单的东西,不过能够实现基础功能,大神看到的话..非常欢迎指导..
//GET方法
axios.get(url, {
params: { 'key': 'value' }
}).then(function (response) {
alert(''.concat(response.data, '\r\n', response.status, '\r\n', response.statusText, '\r\n', response.headers, '\r\n', response.config));
}).catch(function (error) {
alert(error);
});
//对应服务端获取数据
//POST方法
var params = new URLSearchParams();
params.append('key', 'value');
axios.post(url, params).then(function (response) {
alert(''.concat(response.data, '\r\n', response.status, '\r\n', response.statusText, '\r\n', response.headers, '\r\n', response.config));
}).catch(function (error) {
alert(error);
});
//对应服务端获取数据
此种写法猜测应该只是一种比较简单的实现,希望能够帮到其他人,同时希望高手指教;
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步