Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

206
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!