日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > vue >内容正文

vue

前端vue的get和post请求

發布時間:2023/12/13 vue 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 前端vue的get和post请求 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

vue的get和post需要兩個文件vue.js和vue-resource.js

以下是實現的代碼,可以參考一下,需要注意的接口的請求需要考慮跨域的問題,其次就是訪問頁面需要在tomcat下訪問,否則也會報跨域的問題

<!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="utf-8" /> <title>test</title> <meta name="author" content="xiewg@cebserv.com" /> <meta name="copyright" content="www.doyoe.com" /> <script src="js/vue.js"></script> <script src="js/vue-resource.js"></script> <script src="js/jquery.min.js"></script> <style> p~p{color:#f00;} </style> </head> <body> <div id="app"> <table> <tr v-for="item in message"> <td>{{item.expertId}}</td> <td>{{item.categoryName}}</td> </tr> </table> <button v-on:click="greet">get</button> <button v-on:click="postgreet">post</button> </div><script type="text/javascript"> //var books={[]}; //{ // [ // {"id":1,"author":"曹雪芹","name":"紅樓夢","price":32}, // {"id":2,"author":"施耐庵","name":"水滸傳","price":30}, // {"id":"3","author":"羅貫中","name":"三國演義","price":24}, // {"id":4,"author":"吳承恩","name":"西游記","price":20} // ] //} new Vue({ el: '#app', data:{ message: [ {"id":1,"author":"曹雪芹","name":"紅樓夢","price":32}, {"id":2,"author":"施耐庵","name":"水滸傳","price":30}, {"id":"3","author":"羅貫中","name":"三國演義","price":24}, {"id":4,"author":"吳承恩","name":"西游記","price":20} ] }, created: function () { //this.greet(); }, ready:function(){ // this.greet(); }, methods:{greet: function (event) { //`this` 在方法里指向當前 Vue 實例 this.$http.get('http://172.16.1.218:58080/API/app/expertCategory/getQuestionList?expertCategoryId=2').then(function(data){ //this.books=data.body.data; alert(data.body.returnCode); this.message=data.body.resultData; //this.$set('books', data.body); },function(res){ console.log(res.status); }); //alert('Hello ' + this.book + '!') //`event` 是原生 DOM 事件 // if (event) { // alert(event.target.tagName) // } }, postgreet: function (event) { //`this` 在方法里指向當前 Vue 實例 this.$http.post('http://localhost:8080/customer/getCustomer',{param:1111}).then(function(data){ //this.books=data.body.data; alert(data.body.message); //this.message=data; this.greet(); },function(res){ console.log(res.status); }); //alert('Hello ' + this.book + '!') //`event` 是原生 DOM 事件 // if (event) { // alert(event.target.tagName) // } }, } }) </script> </body></html>

  

?

轉載于:https://www.cnblogs.com/xwgcxk/p/8855682.html

總結

以上是生活随笔為你收集整理的前端vue的get和post请求的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。