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>
相关推荐
用户279650435612 小时前
Narwhals:DataFrame 库的轻量兼容层
github
拉拉肥_King3 小时前
Vue 3 主题切换深度解析:从炫酷动画到零闪烁方案
前端·vue.js
右耳朵猫AI3 小时前
GitHub周趋势2026W22 | AI编程工具、知识图谱、自托管、AI代理、代码智能
人工智能·github·ai编程
逻极4 小时前
Git 从入门到精通:版本控制协作实战指南
git·github·分支管理·版本控制
杨梦馨4 小时前
万级数据表格卡死?Web Worker 一招搞定
前端·javascript·vue.js
用户7459571748405 小时前
hug:写 Python API,几行代码就够了
github
DogDaoDao5 小时前
【GitHub】VoxCPM2 实战全解析:原理、部署与效果对比
深度学习·大模型·github·音频·语音模型·tss·文本生成语音
哈撒Ki7 小时前
快速入门vue3与常见面试题
前端·vue.js·面试
云水一下8 小时前
Vue.js从零到精通系列(一):初识Vue——背景、环境与第一个应用
前端·javascript·vue.js
朱涛的自习室8 小时前
Munk AI 正式开源:一个“自我进化”的 AI 测试引擎
android·人工智能·github