vue_ajax 請求

yarn add vue-resource axioshtml

npm install --save axios pubsub-jsvue

// import VueResource from "vue-resource"ios

// Vue.use(VueResource);git

import axios from "axios";github

mounted: {npm

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

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

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

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

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/

相關文章
相關標籤/搜索