<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>axios</title> </head> <script type="text/javascript" src="js/vue.js" ></script> <script type="text/javascript" src="js/axios.min.js" ></script> <script> window.onload = function(){ //配置是否允许检查代码,方便调试,生产环境中设置为false Vue.config.devtools = true; //检查代码 Vue.config.productioinTip = false; //有强迫症的,可以关掉生产中的提示信息 new Vue({ el:‘#div1‘, methods:{ send(){ axios({ method:‘get‘, url:‘user.json‘ }).then(function(res){ console.log(res.data); }).catch(function(msg){ console.log(msg.status); }); }, getSend(){ axios.get(‘user.php‘,{ params:{ name: ‘李四‘, age: 19 } }).then(res => { console.log(res.data); }).catch(err => { console.log(‘get请求失败:‘+err.status+‘,‘+err.statusText); }) } } }) } </script> <body> <div id="div1"> <button @click="send">axios请求</button> <button @click="getSend">get请求</button> </div> </body> </html>
<?php $name = $_GET[‘name‘]; $age = $_GET[‘age‘]; $msg = ‘用户名:‘.$name.‘,年龄:‘.$age; echo $msg;
本文出自 “Note” 博客,转载请与作者联系!
原文地址:http://3miao.blog.51cto.com/9661385/1980138