There are currently no results available through the pixabay API

My attempts to utilize the Pixabay API have been unsuccessful as I am not receiving any results. After checking with console.log, it seems that the API is not sending any data. Any assistance would be greatly appreciated. Thank you.

Below is my code utilizing Vue.js:

<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>
        
        <div class="gallery" id="gallery">
        
            <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>
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>

Answer №1

When you press the enter key, it will trigger form submission. The prevent modifier is currently applied to the input element, but it should actually be on the <form> element:

<form @submit.prevent>

You can then remove it from the keypress event listener like this:

v-on:keyup.enter="search"

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Steps to Create Javascript Image Zoom Effect on Mouse Hover

Looking to implement a feature on my website located at www.thetotempole.ca/javas2.html/. Basically, I have a table with images and I want them to enlarge when a user hovers over them and return to normal when the cursor is moved away. Is there a way to ac ...

Concealing the Placeholder of Div Elements in TinyMCE

I've incorporated TinyMCE into my custom TextBox and TextArea, but I'm struggling to display a placeholder within these elements. Initially, I attempted to implement a placeholder, which worked when TinyMCE was inactive. However, once activated, ...

Participant joins in the game table and reacts

I am looking to set up a table where players can join and have their usernames displayed at the bottom of the screen just like in other games. How can I achieve this? export const GameStart = (props) => { const params = useParams(); const gameID = p ...

Implementing Observable in a function is a simple and effective way to

According to luwojtaszek answer in this topic: How to Export JSON to CSV or Excel - Angular 2 I tried out the following code: public exportAsExcelFile(json: any[], excelFileName: string): void { const worksheet: XLSX.WorkSheet = XLSX.utils.json_to_s ...

Conceal the loading image once the AJAX function has been successfully

I've been trying to figure out a way to load heavy images after an ajax call using animated GIF as a pre-loader, but haven't found a satisfactory solution yet. Here's the code snippet I'm currently using: function loadProducts(url) { ...

What causes my paragraph textContent to vanish after briefly displaying its value?

As a beginner in JavaScript and HTML, I am taking on the challenge of learning these languages from scratch independently. I have encountered an issue with my code where the word "Hi!" briefly flashes below the "Click Me!" button before disappearing compl ...

Attaching a function to the "onselect" event that manages the character limit within an input text field

I have been developing a function to restrict the number of characters a user can enter into a text field. Here's what I have so far: $.fn.restringLength = function (id, maxLen) { $(id).keypress(function(e){ var kCode = ...

Maintain the username data after refreshing the page in React by utilizing local storage

I'm attempting to manage the value of username using local storage. Upon page load, the user should be greeted with a heading that says welcome John. Additionally, I want this value to persist when the page is reloaded. However, upon loading the page ...

Picture in the form of a radio button

Is there a way to use an image instead of a radio button in my AngularJS form? I have managed to hide the radio button using CSS, but it disables the checked event. How can I make the image clickable? position: absolute; left: -9999px; Here is the code s ...

Numeric Input Box: Show gaps

I have numeric input boxes in my HTML/PHP/JS application where users will be entering numbers with 4 to 7 digits. However, I want the users to see spaces between every third digit for better readability. For instance, User types: 8000 Us ...

What is the process for including a new button in the infowindow attached to a marker?

This is a JavaScript code snippet that initializes a map using the Google Maps API. It creates a marker at Uluru in Australia and opens an info window with some content when the marker is clicked. function initMap() { var uluru = {lat: -25.363, lng: 131 ...

Using the codesnippet feature in CKEditor in combination with highlight.js

I am currently experimenting with implementing the highlight.js library in conjunction with the CKEditor addon called CodeSnippet. Although I have successfully integrated the CodeSnippet addon into my CKEditor, the code is not being properly detected, col ...

Restricting the number of characters allowed for text messages and keeping track of the count

I am attempting to implement a character limiter for an html textarea using JavaScript. Additionally, I want to include a total character counter. Unfortunately, the code I have written isn't functioning as expected. Can anyone identify where my mist ...

Utilize event delegation to retrieve the data attribute

Working great for me, able to access data-club-id: <!-- example --> <a class="clubCode" href="" data-club-id= "1234">join with the code</a> $("a.clubCode").on("click",function(e){ e.preventDefault(); var clubId = $(this) ...

Tips on bringing data from a php file into a javascript variable

I'm faced with a challenge where I need to extract data from a MySQL database using a PHP file and then store that data in a JavaScript array for plotting purposes with jQuery's flot library. Has anyone encountered a similar situation and found a ...

Ionic app encounters issue fetching local JSON data

I have been working on my Ionic application and I encountered an issue when trying to load local JSON data into it. I set up a http.get in my javascript to retrieve the data, but for some reason it's not showing up in the application. It seems like th ...

Refreshing the page to dynamically alter background and text hues

I'm currently dealing with a website that generates a random background color for a div every time it is refreshed. I have a code that successfully accomplishes this: var colorList = ['#FFFFFF', '#000000', '#298ACC', &ap ...

Using Javascript to place an image on top of another image (specifically for a close button)

I need help figuring out how to overlay a close icon image on top of another image using JavaScript. Specifically, I want to position the close icon in the top right corner of the image. Current code snippet: function drawImages(imagevalue){ var ar ...

Create a new template following rendering in VueJS

I am facing an issue while using the datatable jQuery plugin with vueJs. Whenever I try to use the render function of the datatable and include vueJs code like @click, it doesn't get interpreted. Instead, in the source code, @click is visible but noth ...

Unit Test: What is the proper way to activate a trigger event on an input that triggers a function in Vuex?

I am working with a bootstrap vue component: <b-form-input v-model="currentUser.name" placeholder="Name *" name="name" @input="checkSubmitStatus()" ></b-form-input> In the methods sec ...