這篇文章給大家分享的是有關(guān)php如何返回數(shù)據(jù)給vue的內(nèi)容。小編覺得挺實用的,因此分享給大家做個參考。一起跟隨小編過來看看吧。
php怎么返回數(shù)據(jù)給vue
1、首先vue發(fā)起網(wǎng)絡(luò)請求可以使用axios庫
1)安裝axios
npm install axios --save
2)Vue使用axios
import axios from "axios"; //將$axios掛在原型上,以便在實例中能用 this.$axios能夠拿到 Vue.prototype.$axios = axios;
3)發(fā)起get請求
this.$axios.get('/localhost/userinfo.php?userid=10001') .then(function (response) { console.log(response); }) .catch(function (error) { console.log(error); });
2、php相應(yīng)請求
10001,'name'=>'老馬','age'=>56); exit(json_encode($arr));
vue手動php返回數(shù)據(jù)就會打印出來
{userid: 10001, name: "老馬", age: 56}
這樣,php返回數(shù)據(jù)給vue的案例就完成了。
感謝各位的閱讀!關(guān)于php如何返回數(shù)據(jù)給vue就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,讓大家可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!