当前位置:首页 » 《随便一记》 » 正文

【Vue2.0】—github小案例(二十三)_m0_46374969的博客

0 人参与  2022年05月22日 08:19  分类 : 《随便一记》  评论

点击全文阅读


【Vue2.0】—github小案例(二十三)

在这里插入图片描述

<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="sendData">Search</button>
    </div>
  </section>

</template>

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

          }
        )
      }
    }
  }

</script>

<style>

</style>


点击全文阅读


本文链接:http://zhangshiyu.com/post/40567.html

请求  更新  数据  
<< 上一篇 下一篇 >>

  • 评论(0)
  • 赞助本站

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

关于我们 | 我要投稿 | 免责申明

Copyright © 2020-2022 ZhangShiYu.com Rights Reserved.豫ICP备2022013469号-1