好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

php怎么返回数据给vue

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网其它相关文章!

查看更多关于php怎么返回数据给vue的详细内容...

  阅读:49次