学习vue和nodejs的过程中,涉及到了axios,今天为了测试,写了get和post两个方法来跟node服务端交互,结果由于header和参数弄了很久,在此记录一下,同时分享;html
因为刚接触axios,在测试方法中,写的都是很简单的东西,不过可以实现基础功能,大神看到的话..很是欢迎指导..vue
//GET方法node
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);
});ios
//对应服务端获取数据 axios
//POST方法app
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);
});post
//对应服务端获取数据学习
此种写法猜想应该只是一种比较简单的实现,但愿可以帮到其余人,同时但愿高手指教;测试