PHP速学教程(入门到精通)
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
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免费学习视频:立即学习
踏上前端学习之旅,开启通往精通之路!从前端基础到项目实战,循序渐进,一步一个脚印,迈向巅峰!
已抢7213个
抢已抢94858个
抢已抢14827个
抢已抢52071个
抢已抢194764个
抢已抢87280个
抢