vue請求數據有Vue-resource、Axios、fetchJsonp三種方式。
Vue-resource是Vue官方提供的插件,axios與fetchJsonp是第三方插件。
- 首先安裝
npm安裝:npm install vue-resource --save 或者 cnpm install vue-resource --save
- 在main.js入口文件中引入vue-resource:
如:import VueResource from 'vue-resource'
- 在引入之後要使用這個插件:Vue.use(VueResource)
不使用的話會報錯: - 再啓動項目:npm run dev 回車
在項目中用this.$http.get(地址).then((response)=>{},function(err){})等等使用。 - 瀏覽器訪問就可以看到請求的數據啦!!!完結......