new Vue({
el: '.box',
data: {},
methods: {
get: function() {
axios({
method: 'post',
url: 'post.php',
data: {
a: '1'
}
}).then(function(response) {
alert(response.data);
}).catch(function(error) {
alert(error);
});
}
}
});
post.php 文件
$a=$_POST['a'];
$b=$_POST['b'];
echo $a;
大家帮我看看是什么原因,是post请求还需要转换吗
首先,可以试着把axios请求部分换成:
另外,由于axios默认发送数据时,数据格式是Request Payload,而并非我们常用的Form Data格式,PHP后端未必能正常获取到,所以在发送之前,需要使用qs模块对其进行处理。