Home >Backend Development >PHP Problem >How to return data to vue in php
How does php return data to vue
1. First, vue can use the axios library to initiate a network request.
Recommended learning: Vue framework video tutorial
1) Install axios
npm install axios --save
2) Vue uses axios
import axios from "axios"; //将$axios挂在原型上,以便在实例中能用 this.$axios能够拿到 Vue.prototype.$axios = axios;
3) Initiate a get request
this.$axios.get('/localhost/userinfo.php?userid=10001') .then(function (response) { console.log(response); }) .catch(function (error) { console.log(error); });
2. PHP corresponding request
<?php header('Content-Type:application/json; charset=utf-8'); $arr = array('userid'=>10001,'name'=>'老马','age'=>56); exit(json_encode($arr));
vue manual php return data will be printed out
{userid: 10001, name: "老马", age: 56}
In this way, the case of php returning data to vue is completed.
The above is the detailed content of How to return data to vue in php. For more information, please follow other related articles on the PHP Chinese website!