Vue-resource安裝過程及使用方法解析
1、安裝
npm install vue-resource --save
2、在main.js中添加
import VueResource from ’vue-resource’//全局注冊Vue.use(VueResource)
3、vue-resource發(fā)送請求
a)對象參數(shù),post請求
this.$http.post(’http://127.0.0.1:8081/getUserByParam’, { userName: this.username, sex:this.sex }).then((response) => { })
b)get請求
this.$http.get(’http://127.0.0.1:8081/getUserById’,{ params:{id:2}//注意,get請求一定要加params,post請求不需要 }).then((response) =>{ this.list=response.body console.log(this.list) });
c) json參數(shù)post請求,和對象參數(shù)post請求一樣
this.$http.post(’http://127.0.0.1:8081/getUserByJson’, { 'id':'11', 'userName':'jie' }//注意,get請求一定要加params,post請求不需要 ).then((response) =>{ this.list=response.body console.log(this.list) })
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關文章:
1. 學python最電腦配置有要求么2. Spring security 自定義過濾器實現(xiàn)Json參數(shù)傳遞并兼容表單參數(shù)(實例代碼)3. JAMon(Java Application Monitor)備忘記4. Java8內(nèi)存模型PermGen Metaspace實例解析5. python中用Scrapy實現(xiàn)定時爬蟲的實例講解6. 基于python實現(xiàn)操作git過程代碼解析7. python使用QQ郵箱實現(xiàn)自動發(fā)送郵件8. Python Scrapy多頁數(shù)據(jù)爬取實現(xiàn)過程解析9. 解決redis與Python交互取出來的是bytes類型的問題10. Python 的 __str__ 和 __repr__ 方法對比
