首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >pixabay api不提供任何结果

pixabay api不提供任何结果
EN

Stack Overflow用户
提问于 2020-12-05 23:27:21
回答 1查看 64关注 0票数 2

所以我尝试使用来自pixabay网站的api,但是我没有任何结果,api没有发送任何结果,我使用console.log检查了它,我希望你们能给我一点帮助,谢谢。

这是使用vuejs的代码,所以我试图使用来自pixabay网站的api,但是我没有任何结果,api没有发送任何结果,我使用console.log检查它,我想从你们那里得到一点帮助谢谢你们。

下面是使用vuejs的代码

代码语言:javascript
复制
 <template>
    <section>
    <div class="row">
    
    <form class="form-inline d-flex justify-content-center md-form form-sm mt-0">
      <i class="fas fa-search" aria-hidden="true"></i>
      <input class="form-control form-control-sm ml-3 w-75" type="text" placeholder="Search"
        aria-label="Search" v-model="searchText" v-on:keyup.enter.stop.prevent="search">
    </form>
    
    </div>
    <!-- Grid row -->
    
    <!-- Grid row -->
    <div class="gallery" id="gallery">
    
      <!-- Grid column -->
      <div class="mb-3 pics" v-for="image in images" :key="image.id"  >
        <img class="img-fluid" :src="image.largeImageURL"  alt="">
      </div>
     
    
    </div>
    </section>
    </template>
    <script>
    // @ is an alias to /src
    import HelloWorld from "@/components/HelloWorld.vue";
    import axios from 'axios'
    export default {
      name: "Home",
      components: {
        HelloWorld,
      },
        data () {
        return {
          searchText: '',
        amount: 15,
        apiUrl: 'https://pixabay.com/api/',
        apiKey: '19405941-132a0646104b54c8459f0746c',
        images: []
        }
      },
      mounted () {
       
      },
      methods:{
        search:function(event){
    
     axios
          .get( `${this.apiUrl}?key=${this.apiKey}&q=${this.searchText}`)
          .then(response => (this.images = response.data.hits))
    console.log(this.images)
         
        }
        
      }
    };
    </script>
    >
EN

回答 1

Stack Overflow用户

发布于 2020-12-05 23:44:08

按enter键即可提交表单。prevent修饰符位于输入上,但应位于<form>

代码语言:javascript
复制
<form @submit.prevent>

并且可以将其从您的按键事件侦听器中删除:

代码语言:javascript
复制
v-on:keyup.enter="search"
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65158581

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档