Vue-51、Vue技术github案例(发送ajax)

1、在index引入bootstrap.csss (注意第三方css库最好在indxe里面引入)

2、List.vue源码

javascript 复制代码
<template>
        <div class="row">
            <div v-show="users.length" class="card" v-for="p in users" :key="p.login">
                <a :href="p.html_url" target="_blank">
                    <img :src="p.avatar_url" style='width: 100px'/>
                </a>
                <p class="card-text">p.login</p>
            </div>

<!--            展示欢迎词-->
            <h1 v-show="isFirst">欢迎使用</h1>

            <h1 v-show="isLoading">加载中</h1>

            <h1 v-show="errMsg">{{errMsg}}</h1>
        </div>
</template>
<script>
    export default {
        name: "List",
        data(){
            return{
                users:[],
                isFirst:true,
                isLoading:false,
                errMsg:''
            }
        },
        methods:{
            getUserList(data,isFirst,isLoading,errMsg){
                this.users = data;
                this.isFirst= isFirst;
                this.isLoading = isLoading;
                this.errMsg = errMsg;
            }
        },
        mounted() {
            this.$bus.$on('getList',this.getUserList);
        },
        beforeDestroy() {
            this.$bus.$off('getList');
        }
    }
</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>

3、Search.vue源码

javascript 复制代码
<template>
    <div>
        <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="search">Search</button>
            </div>
        </section>
    </div>
</template>
<script>
    //接口地址  https://api.github.com/search/users?q=xxx
    import axios from 'axios';
    export default {
        name: "Search",
        data(){
          return{
              keyWord:'',
          }
        },
        methods:{
            search(){
                //请求前更新数据List数据
                this.$bus.$emit('getList',[],false,true,'');
                axios.get(`https://api.github.com/search/users?q=${this.keyWord}`).then(
                    response=>{
                        console.log(response.data.items);
                        this.$bus.$emit('getList',response.data.items,false,false,'');
                        console.log(response.data.items);
                    },error=>{
                        console.log("请求失败");
                        this.$bus.$emit('getList',[],false,false,error.message);
                    }
                )
            }
        }
    }
</script>

<style scoped>

</style>
相关推荐
miofly1 小时前
Inkling 2 Small 发布,基准测试大幅超越前代但不敌同级对手
开源·github
FlyWIHTSKY2 小时前
vue2和vue3有什么区别,用法上有哪些区别
前端·javascript·vue.js
dong_junshuai2 小时前
每天一个开源项目#153 LZ4:用块边界和有序并行换取低延迟
github
Qiongkura3 小时前
开源自荐:CodeYear:把本机 Git 历史变成年度代码手账(本地优先 · 零上传 · 已上 PyPI)
github
用户8351414049493 小时前
我把 claude-mem 跑了一遍:值得学的地方和踩到的坑
github·claude
QuZhengRong4 小时前
【Luck‑Report】 AI 智能报表助手 + RAG 知识库 + 报表引擎 V2.0.9 更新
github·agent·报表·开源项目·数据可视化
ruanno_top6 小时前
能点,但 Tab 不到:两个组件把「可操作」做了一半
vue.js
爱吃烧烤的技术渣6 小时前
别再手写 CRUD 了:我把 Element Plus 的工作量压缩成一份列 schema
前端·vue.js
一条Go6 小时前
能力套餐:菜单、权限、开通范围怎么拆成三层而不打架
后端·github·saas
WeWorker6 小时前
浏览器 Agent 的两种宿命:像素派和工具派
github