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. CentOS郵件服務(wù)器搭建系列—— POP / IMAP 服務(wù)器的構(gòu)建( Dovecot )2. 在JSP中使用formatNumber控制要顯示的小數(shù)位數(shù)方法3. MyBatis JdbcType 與Oracle、MySql數(shù)據(jù)類型對應(yīng)關(guān)系說明4. jsp網(wǎng)頁實(shí)現(xiàn)貪吃蛇小游戲5. django創(chuàng)建css文件夾的具體方法6. 利用CSS制作3D動畫7. ASP中if語句、select 、while循環(huán)的使用方法8. .NET SkiaSharp 生成二維碼驗(yàn)證碼及指定區(qū)域截取方法實(shí)現(xiàn)9. 存儲于xml中需要的HTML轉(zhuǎn)義代碼10. ASP中實(shí)現(xiàn)字符部位類似.NET里String對象的PadLeft和PadRight函數(shù)
