二者其實差異不大,都是基於es6的Promise對象實現的方法vue
vue-resource:ios
main.js =>git
import Vue from 'vue';es6
import VueResource from 'vue-resource';github
Vue.use(VueResource);axios
組件裏面使用=>vue-resource
<template> <div>{{myData}}</div> </template> <script> export default { data() { return { myData:{} } }, created() { this.$http.get(url).then((response) => { // success this.myData = response.body.data; },(error) => { // error console.log(error) }); } } </script>
官方傳送門this
vue-axios:url
axios不能使用use方法spa
main.js=>
import Vue from 'vue';
import axios from 'axios';
Vue.prototype.$axios = axios;
組件裏面使用=>
<template> <div>{{myData}}</div> </template> <script> export default { data() { return { myData: {} } }, created() { this.$axios.get(url).then((response) => { // success this.myData = response.data.data; }, (error) => { // error console.log(error) }); } </script>