vue-resource安裝與使用

vue-resource是vue中使用的請求網絡數據的插件,這個插件是依賴於vue的,簡單說就是用來調接口的。vue

安裝npm

cd 項目目錄 npm i vue vue-resource --save-dev

在入口文件main.js中配置json

import VueResource from 'vue-resource' Vue.use(VueResource)

這樣就能夠直接使用了:網絡

get請求:vue-resource

this.$http.get('地址',{params: {參數}}).then(function(res) { console.log(res) // 響應成功回調
    },function(res) { console.log(res) // 響應錯誤回調
    })

post請求:post

this.$http.post('地址',{參數},{emulateJSON:true}).then( function(res) { console.log(res.data) })

jsonp請求:jsonp

this.$http.jsonp("地址",{params:{參數}}).then( function(res){ console.log(res.data.s) })
相關文章
相關標籤/搜索