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>
相关推荐
Jurio.2 小时前
本机开发 + 多机执行的极简远端运行工具
linux·git·python·github·远程工作
一只蝉nahc2 小时前
vue使用iframe内嵌unity模型,并且向模型传递信息,接受信息
前端·vue.js·unity
MXN_小南学前端5 小时前
前端开发中 try...catch 到底怎么用?使用场景和最佳实践
javascript·vue.js
Hical_W5 小时前
为 C++ Web 框架设计三层 PMR 内存池:从原理到实战
c++·github
Z_Wonderful6 小时前
基于 Vite 的 React+Vue 混部完整模板(含目录结构、依赖清单、启动脚本)
前端·vue.js·react.js
束尘7 小时前
Vue3 项目集成 OnlyOffice 在线编辑 + 自定义插件开发(二):插入功能全实现
数据库·vue.js·mysql
誰在花里胡哨7 小时前
Vue<前端页面装修组件>
前端·vue.js
前端那点事8 小时前
Vue组件通信全场景详解(Vue2+Vue3适配)| 实战必备,新手也能看懂
vue.js
CoovallyAIHub8 小时前
无人机拍叶片→AI找缺陷:CEA-DETR改进RT-DETR做风电叶片表面缺陷检测,mAP50达89.4%
算法·架构·github
CoovallyAIHub8 小时前
混合训练反而更差?VLM Agent在训练前协调跨数据集标注,文档布局检测F-score从0.860提升至0.883
算法·架构·github