当前位置: 首页 > news >正文

写一个githubDemo

1.List组件

<template><div class="container"><!-- 展示用户列表 --><div class="row"><divv-show="info.users.length"v-for="(item, index) in info.users":key="item.id"><div class="col-sm-4 item"><imgclass="hover-image":src="item.avatar_url"@click="targetPage(item.html_url)"/><h5>{{ item.login }}</h5></div><br v-if="isHuanhang(index)" /></div></div><!-- 展示欢迎词 --><h1 v-show="info.isFirst">欢迎使用!</h1><!-- 展示加载中 --><h1 v-show="info.isLoading">加载中....</h1><!-- 展示错误信息 --><h1 v-show="info.errMsg">{{ info.errMsg }}</h1></div>
</template><script>
export default {name: "MyList",data() {return {info: {users: [],isFirst: true,isLoading: false,errMsg: "",},};},methods: {getList(listObj) {//1.第一种方式// this.info = {...this.info,...listObj};//2.第二种方式Object.assign(this.info, listObj);},isHuanhang(index) {if (index % 3 === 0) {return true;} else {return false;}},targetPage(url) {window.open(url, "_blank");},},mounted() {this.$bus.$on("sendList", this.getList);},beforeDestroy() {this.$bus.$off("sendList");},
};
</script><style scoped>
.item {width: 300px;height: 150px;margin-top: 30px;margin-right: 76px;padding: 150px;display: flex;flex-direction: column; /* 纵向排列子项 */justify-content: center; /* 水平居中 */align-items: center; /* 垂直居中 */border: 1px solid #ccc; /* 可选:给容器加个边框 */box-sizing: border-box; /* 包括边框和内边距在内的总宽高 */
}img {width: 150x;height: 120px;
}.hover-image {cursor: pointer; /* 设置鼠标悬浮时光标变成手指 */
}
</style>

2.search 组件

<template><div class="container-xl"><div class="row bc"><divclass="col-xl search-box d-flex flex-column justify-content-end"><h1 class="text-bottom margin-left-dom">Search Github Users</h1></div></div><div class="row bc"><div class="col-xl search-box" ><div class="input-group mb-3 margin-left-dom inputWidth"><inputtype="text"class="form-control"placeholder="enter the name you search"v-model="keyWord"/><button class="btn btn-outline-dark dom-margin" type="button" @click="searchUsers" >Search</button></div></div></div></div>
</template><script>
import axios from 'axios';export default {name: "MySearch",data() {return {keyWord:''}},methods:{searchUsers(){this.$bus.$emit('sendList',{ isFirst: false,isLoading: true,});axios.get('https://api.github.com/search/users',{params:{q:this.keyWord}}).then(res=>{this.$bus.$emit('sendList',{ users: res.data.items,isLoading: false,});},err=>{console.log(err);this.$bus.$emit('sendList',{ users: [],isLoading: false,errMsg: '请求失败,请稍后再试!'});})}}
};
</script><style scoped>.bc{
background-color: rgba(13, 14, 14, 0.313);}.search-box {height: 120px;
}.margin-left-dom {margin-left: 30px;
}.inputWidth {width: 450px;
}
.dom-margin{margin-left: 12px;
}
</style>

3.App组件

<template><div id="appContainer"><MySearch/><MyList/></div>
</template><script>import MySearch from './components/MySearch.vue'import MyList from './components/MyList.vue'
export default {name: "App",components: {MySearch,MyList},methods:{}
};
</script><style></style>

4.引入bootStarp

<!DOCTYPE html>
<html lang=""><head><meta charset="utf-8"><!-- 针对IE浏览器 得一个特殊配置,含义是让IE浏览器以最高得渲染级别渲染页面 --><meta http-equiv="X-UA-Compatible" content="IE=edge"><!-- 开启移动端得理想视口 --><meta name="viewport" content="width=device-width,initial-scale=1.0"><!-- 配置页签图标 --><link rel="icon" href="<%= BASE_URL %>favicon.ico"><!-- 配置网页的标题 package.json name:'vue_test'当作网页的标题 --><link rel="stylesheet" href="<%= BASE_URL %>css/bootstrap.css"><title><%= htmlWebpackPlugin.options.title %></title></head><body><!-- 当浏览器不支持JS时,noscript中的 元素就会被渲染 --><noscript><strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><!-- 容器 --><div id="app"></div><!-- built files will be auto injected --></body>
</html>

5.展示

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • docker 安装minio并配置https域名访问
  • 4款AI 生成 PPT的工具,帮你赶上演示文稿的新趋势!
  • RabbitMQ的核心概念
  • 《九歌· 程序员》
  • 【stm32项目】多功能智能家居室内灯光控制系统设计与实现(完整工程资料源码)
  • kafka运维常用命令
  • 存储实验:华为异构存储在线接管与在线数据迁移(Smart Virtualization Smart Migration 特性)
  • C++ //练习 17.12 使用前一题中的数据结构,编写一个函数,它接受一个问题编号和一个表示真/假解答的值,函数根据这两个参数更新测验的解答。
  • 【轻松拿捏】什么是多态?如何在 Java 中实现多态?
  • 30. 串联所有单词的子串【 力扣(LeetCode) 】
  • 暑假算法刷题日记 Day 10
  • 记录jenkins的一个错误
  • 微信小程序request的请求格式是什么
  • 搭建内网开发环境(一)|基于docker快速部署开发环境
  • ES高级查询Query DSL查询详解、term术语级别查询、全文检索、highlight高亮
  • 实现windows 窗体的自己画,网上摘抄的,学习了
  • 【347天】每日项目总结系列085(2018.01.18)
  • 【刷算法】从上往下打印二叉树
  • 5、React组件事件详解
  • Git初体验
  • happypack两次报错的问题
  • Hibernate最全面试题
  • java8 Stream Pipelines 浅析
  • js面向对象
  • Mithril.js 入门介绍
  • node和express搭建代理服务器(源码)
  • NSTimer学习笔记
  • PHP 小技巧
  • SpiderData 2019年2月25日 DApp数据排行榜
  • SpringCloud(第 039 篇)链接Mysql数据库,通过JpaRepository编写数据库访问
  • Spring技术内幕笔记(2):Spring MVC 与 Web
  • weex踩坑之旅第一弹 ~ 搭建具有入口文件的weex脚手架
  • 海量大数据大屏分析展示一步到位:DataWorks数据服务+MaxCompute Lightning对接DataV最佳实践...
  • 基于游标的分页接口实现
  • 猫头鹰的深夜翻译:JDK9 NotNullOrElse方法
  • 目录与文件属性:编写ls
  • 前嗅ForeSpider中数据浏览界面介绍
  • 前言-如何学习区块链
  • 区块链共识机制优缺点对比都是什么
  • 如何选择开源的机器学习框架?
  • 探索 JS 中的模块化
  • 中文输入法与React文本输入框的问题与解决方案
  • 自定义函数
  • 第二十章:异步和文件I/O.(二十三)
  • 小白应该如何快速入门阿里云服务器,新手使用ECS的方法 ...
  • ​【经验分享】微机原理、指令判断、判断指令是否正确判断指令是否正确​
  • # Apache SeaTunnel 究竟是什么?
  • #1014 : Trie树
  • #systemverilog# 之 event region 和 timeslot 仿真调度(十)高层次视角看仿真调度事件的发生
  • (C++)八皇后问题
  • (delphi11最新学习资料) Object Pascal 学习笔记---第8章第5节(封闭类和Final方法)
  • (附源码)流浪动物保护平台的设计与实现 毕业设计 161154
  • (十) 初识 Docker file
  • (转)Linq学习笔记
  • (转)Scala的“=”符号简介