首页 技术 正文
技术 2022年11月19日
0 收藏 755 点赞 2,327 浏览 1465 个字
<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>Title</title></head><body><div id="example"></div><script type="text/javascript" src="../js/react.development.js"></script><script type="text/javascript" src="../js/react-dom.development.js"></script><script type="text/javascript" src="../js/babel.min.js"></script><script type="text/javascript" src="https://cdn.bootcss.com/axios/0.19.0-beta.1/axios.js"></script><script type="text/babel">    /*    * 需求:    *    1.界面效果如下    *    2.根据指定的关键字在github上搜索匹配的最受关注的库    *    3.显示库名,点击链接查看库    *    4.测试接口:https://api.github.com/search/repositories?q=r&sort=stars    */    class MostStarRepo extends React.Component {        state = {            repoName: '',            repoUrl: ''        }        //在这里发送异步ajax请求        componentDidMount() {            //1.使用axios发送            const url = `https://api.github.com/search/repositories?q=r&sort=stars`;            //因为是promise风格的,所以后面可以使用.then()            axios.get(url).then(response => {                //数据就在response里面                const result = response.data                //使用解构得到想要的数据                const {name, html_url} = result.items[0];                //更新状态                this.setState({repoName: name, repoUrl: html_url})            }).catch((error) => {                alert(error.message)            })            //2.使用fetch发送异步ajax请求            /*fetch(url).then(response => {                return response.json()//response.json()实际上是一个promise对象            }).then(data => {                //得到数据                const {name, html_url} = data.items[0]                //更新状态                this.setState({repoName: name, repoUrl: html_url})            })*/        }        render() {            const {repoName, repoUrl} = this.state            if (!repoName) {                return <h2>LOADING......</h2>            } else {                return <h2>Most star repo is <a href={repoUrl}>{repoName}</a></h2>            }        }    }    ReactDOM.render(<MostStarRepo/>, document.getElementById('example'));</script></body></html>
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,492
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,907
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,740
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,494
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,132
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,295