How to return data to vue in php

angryTom
Release: 2023-02-27 19:10:02
Original
3547 people have browsed it

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
Copy after login

2) Vue uses axios

import axios from "axios"; //将$axios挂在原型上,以便在实例中能用 this.$axios能够拿到 Vue.prototype.$axios = axios;
Copy after login

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); });
Copy after login

2. PHP corresponding request

10001,'name'=>'老马','age'=>56); exit(json_encode($arr));
Copy after login

vue manual php return data will be printed out

{userid: 10001, name: "老马", age: 56}
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!