axios
安装
npm install --save axios
导入并使用
import axios from 'axios'
import Qs from 'qs'
//QS是axios库中带的,不需要我们再npm安装一个
Vue.prototype.axios = axios;
Vue.prototype.qs = Qs;
请求
this.axios.get(url)
.then((response) => {
console.log("axios", response);
console.log(response.data.text[0]);
})
.catch((exception) => {
console.log("axios", exception);
})
vue-resource
安装
npm install --save vue-resource
导入并使用
import VueResource from 'vue-resource'
Vue.use(VueResource);
请求
this.$http.get(url)
.then((data) => { //请求响应成功回调
console.log("vue-resource", data);
this.gettext = data.body.text[0];
}, (error) => { // 请求响应错误回调
console.log("vue-resource", error);
})
.catch(function (exception) { //程序异常回调
console.log("vue-resource", exception);
});