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>
相关推荐
玩代码1 小时前
vue项目安装chromedriver超时解决办法
前端·javascript·vue.js
计算机毕业设计木哥2 小时前
计算机毕业设计选题推荐:基于SpringBoot和Vue的快递物流仓库管理系统【源码+文档+调试】
java·vue.js·spring boot·后端·课程设计
一壶浊酒..2 小时前
ajax局部更新
前端·ajax·okhttp
Wx-bishekaifayuan3 小时前
基于微信小程序的社区图书共享平台设计与实现 计算机毕业设计源码44991
javascript·vue.js·windows·mysql·pycharm·tomcat·php
Moonbit4 小时前
月报 Vol.04 : 新增 async test 与 async fn main 语法,新增 lexmatch 表达式
后端·github·编程语言
九十一5 小时前
vue3事件总线与emit
前端·vue.js
逛逛GitHub5 小时前
发现 4 个贼好玩的 GitHub 项目,相当给劲儿。
github
丨Sky丨夜吻5 小时前
vscode扩展
ide·vue.js·vscode
青灬河5 小时前
实现企业级全栈应用服务框架-Elpis(一)
vue.js·node.js
悟能不能悟7 小时前
用cmd命令修改适配器ip
网络·tcp/ip·github