Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

149
Visualizações
How to fetch and display data on loading and also on search

I would like to fetch and display data on load. After this I would like to display data on search.

Now I only manage to display data on search keyup. I would like to show the list of artist when loading the page as well.

  1. How to display data on load page
  2. How to display data on search

Thanks in advance!

<template>
  <div class="body">
    <div class="searchBar">
      <i class="bi bi-search"></i>
      <input
        placeholder="Search for artists"
        type="text"
        v-model="searchQuery"
        @keyup="searchArtist"
      />
    </div>
    <div class="artists">
      <div
        className="artist__list"
        v-for="artistResult in result"
        :key="artistResult.id"
      >
        <h4>{{ artistResult.name }}</h4>
      </div>
    </div>
  </div>
</template>

<script>
import axios from "axios";
import "./body.css";
export default {
  data() {
    return {
      artists: [],
      result: [],
      searchQuery: "",
    };
  },
  mounted() {
    this.fetchArtists();
  },
  computed: {
    filteredResult() {
      const res = this.result;
      const search = this.searchQuery;
      if (!search) {
        return res;
      }
      return res.filter((item) =>
        item.name.toLowerCase().includes(search.toLowerCase())
      );
    },
  },
  methods: {
    searchArtist() {
      axios
        .get(`http://localhost:3000/artists?q=${this.searchQuery}`)
        .then((response) => {
          this.result = response.data;
        })
        .catch((error) => {
          console.error(error);
        });
    },
    fetchArtists() {
      axios
        .get("http://localhost:3000/artists")
        .then((response) => {
          this.artists = response.data;
        })
        .catch((error) => {
          console.error(error);
        });
    },
  },
};
</script>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

On fetch I need it to bind the api response to the empty array result.

    return {
      result: [],
      searchQuery: "",
    };
  },
fetchArtists() {
      axios
        .get("http://localhost:3000/artists")
        .then((response) => {
          this.result = response.data;
        })
        .catch((error) => {
          console.error(error);
        });
    },
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda