Vue-resource安裝過程及使用方法解析
1、安裝
npm install vue-resource --save
2、在main.js中添加
import VueResource from 'vue-resource' //全局注冊(cè) Vue.use(VueResource)
3、vue-resource發(fā)送請(qǐng)求
a)對(duì)象參數(shù),post請(qǐng)求
this.$http.post('http://127.0.0.1:8081/getUserByParam',
{
userName: this.username,
sex:this.sex
}).then((response) => {
})
b)get請(qǐng)求
this.$http.get('http://127.0.0.1:8081/getUserById',{
params:{id:2}//注意,get請(qǐng)求一定要加params,post請(qǐng)求不需要
}).then((response) =>{
this.list=response.body
console.log(this.list)
});
c) json參數(shù)post請(qǐng)求,和對(duì)象參數(shù)post請(qǐng)求一樣
this.$http.post('http://127.0.0.1:8081/getUserByJson',
{
"id":"11",
"userName":"jie"
}//注意,get請(qǐng)求一定要加params,post請(qǐng)求不需要
).then((response) =>{
this.list=response.body
console.log(this.list)
})
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
一文讀懂vue動(dòng)態(tài)屬性數(shù)據(jù)綁定(v-bind指令)
這篇文章主要介紹了vue動(dòng)態(tài)屬性數(shù)據(jù)綁定(v-bind指令)的相關(guān)資料,文中講解非常細(xì)致,代碼幫助大家更好的理解和學(xué)習(xí),感興趣的朋友可以了解下2020-07-07
vue使用?vue-socket.io三種方式及踩坑實(shí)例解析
這篇文章主要為大家介紹了vue使用?vue-socket.io三種方式及踩坑實(shí)例解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-09-09
學(xué)習(xí)Vue框架中必掌握的重點(diǎn)知識(shí)
這篇文章主要介紹了學(xué)習(xí)Vue中必掌握的重點(diǎn)知識(shí),想了解vue的同學(xué)可以參考下2021-04-04
vue使用localStorage保存登錄信息 適用于移動(dòng)端、PC端
這篇文章主要為大家詳細(xì)介紹了vue使用localStorage保存登錄信息 適用于移動(dòng)端、PC端,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-05-05
vue使用echarts實(shí)現(xiàn)三維圖表繪制
這篇文章主要為大家詳細(xì)介紹了vue如何在項(xiàng)目中使用echarts實(shí)現(xiàn)三維圖表的繪制,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以參考一下2023-08-08

