axios方法get及post代码示例

 show: function(){
//get方式

//赋值给变量self
var self = this;

var url = "hotcity.json";
axios.get(url,{
params:{
username: "金星老师"
}
})
.then(function (response) {
self.stu = response.data.data.hotCity;
console.log(response.data.data.hotCity);
})
.catch(function (error) {
console.log(error);
})

}





show: function(){
//post方式
//var url = "http://bugwhy.com/php/index/getNews.php";
var url = "http://localhost:8000/login";
axios.post(url,{
name: this.username,
password: this.password
},{
"headers": {"Content-Type": "application/x-www-form-urlencodeed"}
}).then(function(res){
console.log(res.data);
})
.catch(function (error) {
console.log(error);
})

}
posted @ 2017-11-16 01:51  goodman8  阅读(475)  评论(0编辑  收藏  举报