时间:2021-07-01 10:21:17 帮助过:126人阅读

php怎么返回数据给vue
1、首先vue发起网络请求可以使用axios库
推荐学习:Vue框架视频教程
1)安装axios
npm install axios --save
2)Vue使用axios
import axios from "axios"; //将$axios挂在原型上,以便在实例中能用 this.$axios能够拿到 Vue.prototype.$axios = axios;
3)发起get请求
this.$axios.get('/localhost/userinfo.php?userid=10001')
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});2、php相应请求
<?php
header('Content-Type:application/json; charset=utf-8');
$arr = array('userid'=>10001,'name'=>'老马','age'=>56);
exit(json_encode($arr));vue手动php返回数据就会打印出来
{userid: 10001, name: "老马", age: 56}这样,php返回数据给vue的案例就完成了。
以上就是php怎么返回数据给vue的详细内容,更多请关注Gxl网其它相关文章!