Orestis uRic
Orestis uRic

Reputation: 369

hide buttons based on query string

I'm building a small forum app with Laravel and Vue and currently i'm adding filter buttons to fetch threads based on the filter button.

For example, in a Vue component, i have the following button, which essentially makes a get request to the back-end and fetches the threads created by the authenticated user

<a href="/threads?myThreads=1"> My Threads </a>

But in addition to the button above i have other filters as well

  1. Threads i have replied to
  2. Threads that were created 7 days ago

However, i want to hide the clicked buttons based on the query strings

window.location.href

For example if i click the button My Threads, then the href will be

/threads?=myThreads=1

In this case i want to hide the button My Threads, based on the href.

My question

Is this a bad approach ? To make decisions based on the href.

Should i try a different approach ? Such as, passing data from the backend to to front end

Upvotes: 0

Views: 249

Answers (1)

Stark Buttowski
Stark Buttowski

Reputation: 1849

To get query params,

this.$route.query.myThreads

You can use the snippet to get the query params value.

To hide the button,

<a href="/threads?myThreads=1" v-if="query !== 1"> My Threads </a>

where query is containing the query params.

Upvotes: 1

Related Questions