Vuetify v-btn routing active class issues - vue.js

I'm writing a CRUD app using Vue with Vuetify. I have some links defined as v-btns using the "to" attribute. I've noticed that when clicking on buttons, the active button usually changes so that the button corresponding to the user's current location is highlighted. However, I have two routes that look like this:
"/songs/new"
"/songs"
The v-btn's have the following "to" attributes:
to:"/songs/new"
to:"/songs"
However, when clicking on the button that directs to "/songs/new", vuetify sets both buttons to be active. Any idea why it does this?

You need to make use of exact attribute.
<v-btn to="/songs/new" exact>Songs</v-btn>
<v-btn to="/songs" exact>New Song</v-btn>
Now the button will get active class only if you were in exactly route.
Also you can make use of exact-active-class to use custom active classes.

Related

How to use `ElButton` as a link using Element Plus and Vue.js

I'm using Element Plus 2.2.28 and Vue.js 3.2.45.
I want to have a button like this:
<el-button>Contact</el-button>
When I click the button, I want it to behave like a link tag using mailto:someone#example.com.
I tried this:
<el-button href="mailto:someone#example.com">Contact</el-button>
However, this doesn't work.
I could use pure JS in the #click event of the button, but I understand this is not recommended.
Since you want to click on the button to redirect you, then you do not need any other functionality that the el-button offers. As such, you only want the appearance of an el-button. Therefore, you can use the el-button class instead on an anchor tag as follows;
<a class="el-button" href="mailto:someone#example.com">Contact</a>

Vuejs Hide/Show Elements refreshes when Routes change

I have been developing a Vue project and something caught my attention today. I used checkboxes with some sytling (I use them as toggle switches) throughout the project and thanks to these elements, I show or hide some elements and components. Toggle elements control specific data within each component. When the data istrue, some elements are displayed on the page and when false, they are hidden. What I noticed today is a little interesting. There is probably a simple solution, but although I have been searching the internet for a while, I haven't found a solution yet.
Here is the thing;
Let's say I am at the About page of my project. I used my toggle switches and now some of my elements and some sub components are displaying in the About.vue. Then I go and visit my Services.vue page and showing and hiding some elements and sub components as well. By the way, almost all of these pages have forms and I save these forms to local storage. When I return to My About page from my Services page, I see that the elements I activated have been restored. In other words, each component welcomes me with its default state when it is returned from another component. What I want to see is, If I go and check some checkboxes to show some element, No matter how long I roam between other routes, I want those elements to remain visible or hidden when I come back. For example, a toggle element must be activated to write a username and password on a component. After activating the toggle element, the user types the username and password and clicks the Save button. Then he continues to browse many areas of the project and when he returns, he sees that the toggle element is inactive and the username and password are not entered. I don't want it to be that way. How do I fix this?
you can use vuex for solved this problem.
https://vuex.vuejs.org/
Vuex is a state management pattern + library for Vue.js applications. It serves as a centralized store for all the components in an application, with rules ensuring that the state can only be mutated in a predictable fashion. It also integrates with Vue's official devtools extension (opens new window)to provide advanced features such as zero-config time-travel debugging and state snapshot export / import.

Extending vuetify v-btn component, adding custom click event

I am trying to create component which would extend v-btn in such a way that every time I click a button, it should emit short beep, and disable the button for 5 seconds.
It would be ideal for the button to change color while disabled.
This is a problem, since color is a property, and I can't overwrite it's value...
Also, when I try to invoke super.click(e), I get an error.
You can check example here: https://codesandbox.io/s/elegant-glade-pnhqx
Your Btn component should just "use" v-btn rather than extending it.
v-bind="$attrs" is to copy any <btn>'s attribute onto <v-btn>.
#click event is captured and reemited as-is after doing what needs to be done
See https://codesandbox.io/s/immutable-paper-w1wck?file=/src/components/Btn.vue:41-56

strange behavior when trying to re-render data inside slot in vue

I am getting strange behaviour when trying to dynamically update the content of a slot in Vue with Vuetify. I'm sure this is just a function of misunderstanding how slots work.
I have a slot in a custom component, like so:
<template #selectButtons="slotProps">
<v-icon #click="dropToggle(slotProps.player)"
:color="dropColor(slotProps.player)"
class="mr-5"
>
fas fa-skull-crossbones
</v-icon>
</template>
When the user clicks on the icon, it is meant to toggle the icon to different colors.
I cannot seem to get dropColor to fire on each click consistently, HOWEVER, the weird part is, if I make some change inside the <v-icon> component, like say I just add {{dropColor(slotProps.player)}} inside the v-icon tags, then all of a sudden the code will work.
But then if I do a full refresh of the page, it stops working. Then I delete that code and put it back in, then it works again!
I have tried forceUpdate and keys on the v-icon tag.
Would appreciate any help
You are trying to pass function dropColor(slotProps.player) as props. The better idea is to replace function to an object or variable and change that object/variable within method dropToggle(slotProps.player) after #click event is firing .

How to implement sidebar with settings for each component

I am just getting started with vuejs and after following a course on udemy I feel ready to dig in. To get started I need some pointers.
Take a look at this screenshot:
I have created a component call it example, when I click on the component I need on the left side of the component to show the settings for just that component. If I change those settings they should only be changed for selected component. If I select the second component settings with its own values should then be displayed to the left.
What is best way to do this? Sidebar on the left should only be visible if the component is clicked/selected. So I am guessing that the sidebar component which we can call settings should be a child of example component so that I can comunicate with this when it should be visible or not.
My question is how do I position the child component to the left like I have "mocked up" on the screenshot. Is it possible to copy settings component html into the left sidebar each time I click an example component?
How would you implement something like this?