axios的get方法
axios({
url: 'http://xxx',
method: 'get' //默认就是get,这个可以省略,
params: {
key: value
}
})
从写法上看 axios的get方法与ajax的相类似
axios的post的方法
//请求头设置在内部
axios({
url: 'http://xxx',
method: 'post',
headers: { //单个请求设置请求头
'Content-Type': "application/x-www-form-urlencoded"
}
})
.then(res => {
console.log( res )
})
.catch( error => {
if( error ){
throw error
}
})
//请求头设置在内部外部
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
new Vue({
el:'#app',
methods: {
post(){
axios({
url:'http://xxx',
method:'post',
}).then(function(data){
console.log(data);
})
}
},
})
axios的post方法需要设置请求头