github搜索案例

这篇具有很好参考价值的文章主要介绍了github搜索案例。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

目录结构 

github搜索案例,vue,github

public/index.html

<!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">
    <!-- 引入第三方样式 -->
    <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>

src/App.vue

<template>
    <div class="container">
        <Search />
        <List />
    </div>
</template>

<script>
import Search from './components/Search'
import List from './components/List'
export default {
    name: 'App',
    components: { Search, List }
}
</script>

src/main.js 

import Vue from 'vue'
import App from './App.vue'
//引入插件
import vueResource from 'vue-resource'

Vue.config.productionTip = false
//使用插件
Vue.use(vueResource)
//创建vm
new Vue({
    el: '#app',
    render: h => h(App),
    beforeCreate(){
        Vue.prototype.$bus=this //安装全局事件总线
    }
})

src/components/List.vue

<template>
  <div class="row">
    <!-- 展示用户列表 -->
    <div v-show="info.users.length" class="card" v-for="user in info.users" :key="user.login">
      <a :href="user.html_url" target="_blank">
        <img :src="user.avatar_url" style='width: 100px' />
      </a>
      <p class="card-text">{{ user.login }}</p>
    </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: 'List',
  data() {
    return {
      info: {
        isFirst: true,
        isLoading: false,
        errMsg: '',
        users: []
      }

    }
  },
  mounted() {
    this.$bus.$on('updateListData', (dataObj) => {
      this.info={...this.info,...dataObj}
    })
  }
}
</script>
<style scoped>
.album {
  min-height: 50rem;
  /* Can be removed; just added for demo purposes */
  padding-top: 3rem;
  padding-bottom: 3rem;
  background-color: #f7f7f7;
}

.card {
  float: left;
  width: 33.333%;
  padding: .75rem;
  margin-bottom: 2rem;
  border: 1px solid #efefef;
  text-align: center;
}

.card>img {
  margin-bottom: .75rem;
  border-radius: 100px;
}

.card-text {
  font-size: 85%;
}
</style>

src/components/Search.vue

<template>
  <section class="jumbotron">
    <h3 class="jumbotron-heading">Search Github Users</h3>
    <div>
      <input type="text" placeholder="enter the name you search" v-model="keyWord" />&nbsp;
      <button @click="searchUsers">Search</button>
    </div>
  </section>
</template>

<script>
export default {
  name: 'Search',
  data() {
    return {
      keyWord: ''
    }
  },
  methods: {
    searchUsers() {
      // 请求前更新List的数据
      this.$bus.$emit('updateListData', { isFirst: false, isLoading: false, errMsg: '', users: [] })
      this.$http.get(`https://api.github.com/search/users?q=${this.keyWord}`).then(
        response => {
          console.log('请求成功了');
          // 请求成功后更新List的数据
          this.$bus.$emit('updateListData', { isLoading: false, errMsg: '', users: response.data.items })
        },
        error => {
          console.log('请求失败了');
          // 请求失败后更新List的数据
          this.$bus.$emit('updateListData', { isLoading: false, errMsg: error.message, users: [] })
        }
      )
    }
  }
}
</script>

github搜索案例,vue,github 

 文章来源地址https://www.toymoban.com/news/detail-556334.html

注意:这里使用vue-resource插件,所以要安装npm i vue-resource(不推荐使用) 

第一种方式:import vueResource from 'vue-resource'  Vue.use(vueResource) this.$http.get(' ').then()

第二种方式:import axios from 'axios' axios.get(' ').then()

 

 

到了这里,关于github搜索案例的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • Github 用户查询案例【基于Vue2全局事件总线通信】

            本次案例是一个基于 Vue2 的全局事件总线通信的仿 Github 用户搜索模块,使用的接口是 Github 官方提供的搜索接口: https://api.github.com/search/users?q=xxx(发送请求时需要将输入的用户名称绑定替换掉xxx),如果对全局事件总线不太熟练的小伙伴可以看这篇文章: http:/

    2024年02月03日
    浏览(40)
  • 【Vue3】2-12 : 【案例】搜索关键词加筛选条件的综合

    本书目录:点击进入 一、【案例】搜索加筛选条件的综合 1.1、逻辑 1.2、效果 1.3、json数据 - 02-data.json 1.4、代码 计算属性 - 绑定list,并过滤 input  双向绑定 - 当input改变时,计算属性过滤name button组 双向绑定  - 当input改变时,计算属性过滤性别

    2024年01月20日
    浏览(36)
  • github搜索技巧探索

    毕设涉及到推荐系统,那么就用搜索推荐系统相关资料来探索一下GitHub的搜搜技巧 1. 基础搜索 动机 :查找GitHub上的推荐系统相关项目。 搜索 :直接输入 “recommender system”。 2. 限定在特定仓库搜索 动机 :有些项目名称直接包含了 “recommend”;有些虽然仓库名里面没包含,

    2024年02月08日
    浏览(25)
  • GitHub高效搜索技巧

    1.排序搜索结果 按交互排序 语法 例子 org:github sort:interactions 匹配 GitHub 拥有的存储库中的问题,按反应和评论的最高组合数排序 org:github sort:interactions-asc 匹配 GitHub 拥有的存储库中的问题,按最少的反应和评论组合数排序 按反应排序 语法 例子 org:github sort:reactions 匹配 GitH

    2024年02月15日
    浏览(25)
  • github搜索技巧笔记

    GitHub Watch按钮 Watch可以理解为 关注的意思 ,默认情况下是Not watching,当选择Watch后,你会收到这个GitHub项目的所有动态。比如:有人发起pull request或者issue等。接收动态方式包括个人通知中心或者邮箱。 如果某个GitHub项目你感兴趣,你想收到这个项目的所有动态,那么就Wa

    2024年02月12日
    浏览(54)
  • 【在GitHub上搜索】

    搜索 GitHub 时,您可以构建匹配特定数字和单词的查询。 注意:以下语法适用于非代码搜索。 有关代码搜索语法的详细信息,请参阅“了解 GitHub 代码搜索语法”。 可以使用  、 = 、  和  =  搜索大于、大于或等于、小于以及小于或等于另一个值的值。 查询 示例 n cats sta

    2024年01月17日
    浏览(17)
  • github搜索方法

    GitHub可以使用搜索功能来查找存储库、代码、问题、提交记录、分支等。 1.进入GitHub主页(https://github.com/) 2.在搜索框中输入您要搜索的或短语,并按“Enter”键。 3.您将被重定向到一个新页面,其中包含有关您的搜索结果的信息。 4.如果要缩小搜索结果,可以使用筛

    2024年02月15日
    浏览(22)
  • GitHub代码搜索限制

    不知道从何时起,GitHub限制了搜索代码的结果,只能获取默认的前100条代码,且不支持排序筛选。 具体表现如下: 搜索 aaa ,共有 22.5M 条数据,我每页展示20条数据,当查看到第5页时,无法继续点击下一页,当通过修改参数查询第6页时,提醒我没有搜索结果。 后翻了一下官

    2024年02月09日
    浏览(21)
  • GitHub高级搜索技巧

    in:name 仓库名称带查询 in:description 仓库描述带查询 in:readme README文件带查询 stars(fork): (=) 数字 star或fork数大于(或等于)指定数字的带查询 stars(fork): 10..20 star或fork数在10到20之间的带查询 size:=5000 限定

    2024年01月17日
    浏览(34)
  • Github的正确搜索方法

    了解搜索语法 从左至右,依次是 watch star fork,下面分别说下他们的具体作用。 下图是Github中各个功能介绍: watch watch翻译过来可以称之为观察,点击watch可以看到如下的列表。 star star 翻译过来应该是星星,但是这个翻译没任何具体意义,这里解释为 关注 或者 点赞 更合适,

    2024年02月04日
    浏览(24)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包