vue_ajax 请求

yarn add vue-resource axios

npm install --save axios pubsub-js

// import VueResource from "vue-resource"

// Vue.use(VueResource);

import axios from "axios";

mounted: {

const url="https://api.github.com/search/users?q=aa"

const url="https://api.github.com/search/repositories?q=v&sort=stars"

// this.$http.get(url).then(response=>{        // vue-resourve

axios.get(url).then(response=>{get(url).then(response=>{        // axios

const result = response.data;

const {name, html_url} = result.items[0];

this.repoName = name;

this.repoUrl = html_url;

}).catch(err=>console.log("请求失败:"+err));

}

源码参见 :http://www.tianxiaxuange.xyz/my-vue/

posted @ 2019-02-18 11:41  耶梦加德  阅读(225)  评论(0编辑  收藏  举报