vue 官方实例教程 抓取git资料 vue获取网络上的资料
发布日期:2021-05-07 19:17:08 浏览次数:24 分类:精选文章

本文共 1563 字,大约阅读时间需要 5 分钟。

gitHub API地址

我们打开如下地址

 

可以看到

  • 点进去可以跳转到
GET /repos/:owner/:repo/issues/:number/comments

owner 代表用户名

上代码h5

  
JS Bin

Latest Vue.js Commit

vuejs/vue@{ {currentBranch}}

js

var apiURL='https://api.github.com/repos/vuejs/vue/commits?per_page=3&sha=';var demo=new Vue({  el:'#demo',  data:{    branches:['master','dev'],    currentBranch:'master',    commits:null  },  created:function(){    this.fetchData();  },  watch:{    currentBranch:'fetchData'  },  methods:{    fetchData:function(){      var xhr=new XMLHttpRequest();      var self=this;      xhr.open('GET',apiURL+self.currentBranch);      xhr.onload=function(){        self.commits=JSON.parse(xhr.responseText);        console.log(self.commits[0].html_url)      }      xhr.send();    }  }});

可以看到遇到了很多新的语法。这里讲解一下

以下是javaScript获取数据 这个很好理解

 

var xhr=new XMLHttpRequest();      var self=this;      xhr.open('GET',apiURL+self.currentBranch);      xhr.onload=function(){        self.commits=JSON.parse(xhr.responseText);        console.log(self.commits[0].html_url)      }      xhr.send();

created 是生命周期 我们也知道了呢

watch:{    currentBranch:'fetchData'  },

就相当于

watch:{    currentBranch:function(){      this.fetchData();    }  },

当 currentBranch的数值 发生变化的时候。就会调用fetchDate()这个方法

:value的写法 vue中冒号是v-bind:的缩写,知道缩写以后,更容易提高我们的效率

b-bind官方讲解

这里用到了v-bind:value="branch"

别的就没有什么新东西啦~~

 

上一篇:vue 官方实例教程 markdown demo
下一篇:Android项目中最火最常用的优秀开源项目

发表评论

最新留言

留言是一种美德,欢迎回访!
[***.207.175.100]2025年04月16日 18时07分16秒