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)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. Jsp中request的3個(gè)基礎(chǔ)實(shí)踐2. jsp EL表達(dá)式詳解3. XML入門的常見問題(一)4. Django ORM實(shí)現(xiàn)按天獲取數(shù)據(jù)去重求和例子5. IntelliJ IDEA 統(tǒng)一設(shè)置編碼為utf-8編碼的實(shí)現(xiàn)6. Python多線程操作之互斥鎖、遞歸鎖、信號(hào)量、事件實(shí)例詳解7. idea設(shè)置自動(dòng)導(dǎo)入依賴的方法步驟8. idea給項(xiàng)目打war包的方法步驟9. Django程序的優(yōu)化技巧10. 怎樣才能用js生成xmldom對象,并且在firefox中也實(shí)現(xiàn)xml數(shù)據(jù)島?
