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

207
Visualizações
Why is Vue not adding view count to a post?
Problem

I'm building a post website with a view count. I am also using firebase. I added the view count so if you click on one of the posts (playlistsin the code) it should add one view to the post.

As you can see the view count is added in the p tag inside the router-link. It is also added in the PlaylistDetails component. The problem is that it updates the view count in the p tag but not in the PlaylistDetails.

So when you click on the router-link, the p tag will update and it will bring you to the playlistdetails component, but there it won't update.

This is my code:

The View Count with Button

<template>
  <div>
    <router-link
      :to="{ name: 'PlaylistDetails', params: { id: playlist.id } }"
      @click="handleViews"
    >
      <div>
        <button>test</button>
        <p>{{ playlist.views }}</p>
      </div>
    </router-link>
  </div>
</template>

<script>
import useDocument from "../composables/useDocument";
import { useRouter } from "vue-router";

export default {
  props: ["playlist"],
  setup(props) {
    const { updateDoc } = useDocument("playlists", props.playlist.id);
    const router = useRouter();

    const handleViews = async () => {
      const res = await updateDoc({
        views: props.playlist.views++,
      });
    //   await router.push({
    //     name: "PlaylistDetails",
    //     params: { id: props.playlist.id },
    //   });
      console.log("add view");
    };

    return {
      handleViews,
    };
  },
};
</script>
The PlaylistDetails component

<p>{{ playlist.views }}</p>
about 4 years ago · Juan Pablo Isaza
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