Home  >  Article  >  Backend Development  >  How to return data to vue in php

How to return data to vue in php

angryTom
angryTomOriginal
2019-10-26 13:57:543628browse

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(&#39;Content-Type:application/json; charset=utf-8&#39;);
$arr = array(&#39;userid&#39;=>10001,&#39;name&#39;=>&#39;老马&#39;,&#39;age&#39;=>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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn