
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
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"
别的就没有什么新东西啦~~
发表评论
最新留言
留言是一种美德,欢迎回访!
[***.207.175.100]2025年04月16日 18时07分16秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
用C#实现封装-徐新帅-专题视频课程
2019-03-05
C语言学习从初级到精通的疯狂实战教程-徐新帅-专题视频课程
2019-03-05
三层框架+sql server数据库 实战教学-徐新帅-专题视频课程
2019-03-05
NAT工作原理
2019-03-05
Processes, threads and goroutines
2019-03-05
c++中的10种常见继承
2019-03-05
E28 LoRa模块透传 定点传输 RSSI测试与MicroPython应用
2019-03-05
Vue学习—深入剖析渲染函数
2019-03-05
Vue学习—深入剖析函数式组件
2019-03-05
简单Makefile的编写
2019-03-05
使用BAT批处理 匹配查找指定文件夹,并在当文件夹下创建空文件
2019-03-05
wxpython的Hello,World代码探索
2019-03-05
【数字图像处理】OpenCV3 学习笔记
2019-03-05
【单片机开发】智能小车工程(经验总结)
2019-03-05
【单片机开发】基于stm32的掌上游戏机设计 (项目规划)
2019-03-05
KeepAlived介绍、配置示例、KeepAlived配置IPVS、调用脚本进行监控
2019-03-05
【Numpy学习】np.count_nonzero()用法解析
2019-03-05
Scala集合-数组、元组
2019-03-05
Flink Standalone集群安装和部署
2019-03-05