axios.get php,vue请求方式axios和axios.get

html>

axios

window.onload = function(){

//配置是否允许检查代码,方便调试,生产环境中设置为false

Vue.config.devtools = true;  //检查代码

Vue.config.productioinTip = false;  //有强迫症的,可以关掉生产中的提示信息

new Vue({

el:'#div1',

data:{

user:{

name: 'lili',

age:20

}

},

methods:{

send(){

axios({

method:'get',

url:'user.json'

}).then(function(res){

console.log(res.data);

}).catch(function(msg){

console.log(msg.status);

});

},

getSend(){

axios.get('user.php',{

params:{

name: '李四',

age: 19

}

}).then(res => {

console.log(res.data);

}).catch(err => {

console.log('get请求失败:'+err.status+','+err.statusText);

})

},

postSend(){

axios.post('server.php',this.user,{

transformRequest:[

function(data){

let params = '';

for(let index in data){

params += index+'='+data[index]+'&';

}

return params;

}

]

}).then(resp => {

console.log(resp.data);

}).catch(err => {

console.log('请求失败:'+err.status+','+err.statusText);

})

},

jsonpSend(){

this.$http.jsonp('https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su',{

params:{

wd:'a' //百度的参数

},

jsonp: 'cb',//可以修改对方请求参数名称

}).then(res => {

console.log(res.data);

})

}

}

})

}

axios请求

get请求

post请求

jsonp请求

$name = $_GET['name'];

$age = $_GET['age'];

$msg =  '用户名:'.$name.',年龄:'.$age;

echo $msg;<?php

$name = $_POST['name'];

$age = $_POST['age'];

$msg =  '用户名:'.$name.',年龄:'.$age;

echo $msg;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值