ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# POST请求 ~~~ <!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14"></script> <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script> <script src="https://cdn.bootcdn.net/ajax/libs/qs/6.10.1/qs.js"></script> <title>Document</title> </head> <body> <div id="app"> <button type="button" @click="getDate">获取数据</button> <p>{{user.name}}=={{user.age}}</p> </div> </body> </html> <script type="text/javascript"> var vm= new Vue({ el:'#app', data:{ user:'1223' }, methods:{ getDate:function (){ data=Qs.stringify({name:'lampol111',age:33}) axios({ method:'post', url:'http://127.0.0.1/index.php', data:data //POST这里是data }).then(res=>{ console.log(res.data) this.user=res.data }) } } }) </script> ~~~ # GET写法: ~~~ <!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14"></script> <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script> <script src="https://cdn.bootcdn.net/ajax/libs/qs/6.10.1/qs.js"></script> <title>Document</title> </head> <body> <div id="app"> <button type="button" @click="getDate">获取数据</button> <p>{{user.name}}=={{user.age}}</p> </div> </body> </html> <script type="text/javascript"> var vm= new Vue({ el:'#app', data:{ user:'1223' }, methods:{ getDate:function (){ data={name:'lampol111',age:33} axios({ method:'get', url:'http://127.0.0.1/index.php', params:data //get这里是params }).then(res=>{ console.log(res.data) this.user=res.data }) } } }) </script> ~~~~~~ <!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14"></script> <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script> <script src="https://cdn.bootcdn.net/ajax/libs/qs/6.10.1/qs.js"></script> <title>Document</title> </head> <body> <div id="app"> <button type="button" @click="getDate">获取数据</button> <p>{{user.name}}=={{user.age}}</p> </div> </body> </html> <script type="text/javascript"> var vm= new Vue({ el:'#app', data:{ user:'1223' }, methods:{ getDate:function (){ data={name:'lampol111',age:33} axios({ method:'get', url:'http://127.0.0.1/index.php', params:data //get这里是params }).then(res=>{ console.log(res.data) this.user=res.data }) } } }) </script> ~~~