Vuetify v-menu component not visible - vue.js

So I've been following the first example on how to create a dropdown menu on Vuetify. I basically copy pasted the entire code to ensure it was done right and added the necessary variables referenced in that example.
The problem I have is that the v-menu and everything within that tag doesn't show up at all. The menu I have for example is using v-btn, and it's visible as long as it's outside the v-menu tag. 'npm run build' and chrome debugger doesn't generate any errors either. I can use other Vuetify components but v-menu doesn't behave as documented...
Any help would be much appreciated.

I managed to make it work.
It is strongly advised to use vue-cli when you create vue projects.
I did the following in the command line:
$> yarn global add #vue/cli
$> vue create vuetify
$> yarn add vuetify
I added Vuetify in main.js:
import Vue from 'vue'
import App from './App.vue'
import Vuetify from 'vuetify'
Vue.config.productionTip = false
Vue.use(Vuetify)
new Vue({
render: h => h(App),
}).$mount('#app')
Then I replaced the content in components\HelloWorld.vue with the example:
<template>
<div class="text-xs-center">
<v-menu offset-y>
<template v-slot:activator="{ on }">
<v-btn
color="primary"
dark
v-on="on"
>
Dropdown
</v-btn>
</template>
<v-list>
<v-list-tile
v-for="(item, index) in items"
:key="index"
#click="test"
>
<v-list-tile-title>{{ item.title }}</v-list-tile-title>
</v-list-tile>
</v-list>
</v-menu>
</div>
</template>
<script>
export default {
data: () => ({
items: [
{ title: 'Click Me' },
{ title: 'Click Me' },
{ title: 'Click Me' },
{ title: 'Click Me 2' }
]
}),
methods: {
test() {
}
}
}
</script>
Then run yarn serve
And the dropdown button behaves as expected, minus the css.

Related

How to append #click navigateTo() event to v-list items props

I am using Nuxt3 with Vuetify3, and I am having trouble getting this to work:
<template>
<v-navigation-drawer
v-model="menu"
class="pa-4"
temporary
>
<v-list
:items="items"
nav
density="compact"
/>
</v-navigation-drawer>
</template>
<script setup lang="ts">
const menu = ref(false);
const items = [
{
title: 'Dashboard',
props: {
'#click': () => {
navigateTo('./dashboard');
},
prependIcon: 'mdi-view-dashboard-variant-outline'
}
},
{
title: 'Orders',
props: {
to: './orders',
prependIcon: 'mdi-package-variant'
}
}
];
</script>
The Orders list-item works as expected, but it is causing other bugs in my app with Nuxt, so I would like to use Nuxt's navigateTo() function. The Dashboard link doesn't have the click event attached.
I have also tried '#click': navigateTo('./dashboard') but this creates an endless navigation loop in Nuxt. I also tried 'v-on:click' and click () {}, but I can't seem to get it to append the click event to the v-list-items.
Obviously I could rewrite this without the shorthand <v-list :items="items" />, but I'm sure there must be a way to do this shorthand.

is there anyway to bind non HTML tags like v-btn to Nuxt's tag prop

So this is the code i type on my editor
<nuxt-link :to="www.test.com" tag="v-btn" /> Link Button </nuxt-link>
apparently v-btn is not an HTML original tag but a vuetify specific one and when i write the code this way it doesn't actually work and i'm not getting the styles that are bind with a v-btn tag.
so i'm wondering if there's actually a way to do this...
ps: wrapping the v-btn with a nuxt-link tag in this way below
<nuxt-link to="www.text.com">
<v-btn>Link Button</v-btn>
</nuxt-link>
makes the button a link and actually works but this can't be used everywhere since some of the vuetify tags are related together and adding non vuetify tags inside it ruins the styles, like this example below which is a case of using a v-btn inside a v-toolbar-item, normally v-btn has a special style inside a v-toolbar-item but when we wrap it with a nuxt-link it loses all the styles.
<v-toolbar-items>
<nuxt-link :to="www.test.com>
<v-btn>Link Button</v-btn>
</nuxt-link>
</v-toolbar-items>
The v-btn component from Vuetify has a nuxt property to handle Nuxt.js:
<v-btn nuxt to="www.text.com">Link Button</v-btn>
See vuetify docs about the "nuxt" property: https://vuetifyjs.com/en/components/buttons/#api
You can access the href="string"
<template>
<v-col class="pb-0">
<v-btn
v-for="(link, i) in links"
:key="i"
depressed
color=""
text
rounded
class="text-none"
:to="link.l"
:href="link.href"
>
{{ link.n }}
</v-btn>
</v-col>
</template>
<script>
export default {
data () {
return {
links: [
{
n: 'About us',
l: '/about-us'
},
{
n: 'Help',
l: '/help'
},
{
n: 'Blog',
l: '/blog'
},
{
n: 'Contact',
l: '/contact'
},
{
n: 'google.com',
href: 'https://www.google.com'
}
]
}
}
}
</script>

Vuetify v-dialog do not show in spite of value attribute equal to true

I am using vuex store state to show/hide Vuetify v-dialog in my NuxtJS app. Following are the code excerpt:
Vuex Store:
export const state = () => ({
dialogOpen: false
});
export const mutations = {
setDialogToOpen(state) {
state.dialogOpen = true;
},
setDialogToClosed(state) {
state.dialogOpen = false;
}
};
export const getters = {
isDialogOpen: state => {
return state.dialogOpen;
}
};
Dialog Component:
<v-dialog
v-model="isDialogOpen"
#input="setDialogToClosed"
max-width="600px"
class="pa-0 ma-0"
>
...
</v-dialog>
computed: {
...mapGetters("store", ["isDialogOpen"])
},
methods: {
...mapMutations({
setDialogToClosed: "store/setDialogToClosed"
})
}
This all works fine but when I redirect from one page to another page like below it stops working.
this.$router.push("/videos/" + id);
I hit browser refresh and it starts working again. Using the Chrome Vue dev tools, I can see the state is set correctly in the store as well as in the v-dialog value property as shown below
In Vuex store
In v-dialog component property
Yet the dialog is not visible. Any clue what is happening?
I am using NuxtJS 2.10.2 and #nuxtJS/Vuetify plugin 1.9.0
Issue was due to v-dialog not being wrapped inside v-app
My code was structured like this
default layout
<template>
<div>
<v-dialog
v-model="isDialogOpen"
#input="setDialogToClosed"
max-width="600px"
class="pa-0 ma-0"
>
<nuxt />
</div>
</template>
Below is the code for index page which replaces nuxt tag above at runtime.
<template>
<v-app>
<v-content>
...
</v-content>
</v-app>
</template>
So, in the final code v-dialog was not wrapped inside v-app. Moving v-app tag to default layout fixed it
<template>
<v-app>
<v-dialog
v-model="isDialogOpen"
#input="setDialogToClosed"
max-width="600px"
class="pa-0 ma-0"
>
<nuxt />
</v-app>
</template>

Vue + Vuetify reuse snackbar / alert

I'm new to Vue I wanted to reuse the snackbar / alert box from vuetify to each of my components. I did it by copy pasting the code for each component which makes it very messy and hard to maintain.
How do I reuse this for each of my view vue component?
Please see my example code below.
Vue component < template >
<v-snackbar
v-model="snackbar.appear"
:color="snackbar.color"
:timeout="snackbar.timeout"
:left="snackbar.x === 'left'"
:right="snackbar.x === 'right'"
:top="snackbar.y === 'top'"
>
<v-row>
<v-icon class="mx-2" size="18" dark>{{ snackbar.icon }}</v-icon>
{{ snackbar.text }}
</v-row>
<v-btn dark text #click="snackbar.appear = false">OKAY</v-btn>
</v-snackbar>
Vue component < script >
snackbar: {
appear: false,
icon: '',
text: '',
color: 'success',
timeout: 2500,
x: 'right',
y: 'top',
},
axios
.post('/api/department-objective', { corporate_objective_id, objective, description })
.then(response => {
this.snackbar.appear = true
this.snackbar.text = response.data.text
this.snackbar.icon = response.data.icon
})
.catch(error => {
console.log(error)
this.alert = true
this.allerror = error.response.data.errors
})
I often add application wide alert messages to the root application's component, like e.g. an App component building up the base layout and bind it's visibility to the presence of an error or notification property in a central vuex store.
See this answer for details
You can create a snackbar component , which you can import in App.vue so that it's available to the every component , you can then trigger this component using vuex store as per you're requirement.
Here's an article which I used while learning to implement the same.
How to create a global snackbar using Nuxt, Vuetify and Vuex..
If you dont want to use nuxt , just refer to the article and you'll get the idea.
you can create a SnackBarComponent and import it on every other Component
App.vue
<template>
<SnackBarComponenent :stuffProp="yourProps" />
</template>
<script>
import SnackBarComponenent from './components/SnackBarComponent'
export default {
components:{
ProfileOverview
}
}
</script>

Vuetify text displaying on the right side of the v-navigation-drawer

I am a new programmer and trying to make a non-toggling side bar, like admin page.
The router-view doesnt display on the right side of the page.
I know that I don't have a href link for each of the navigation list, where and how can I do that?
also, is the Apps causing conflict with the sellingSummary page?
and am I inserting the router-view in the wrong place?
I need help, thank you !!!!
image
<template>
<div>
<v-app id="inspire">
<v-navigation-drawer
stateless
value="true"
>
<v-list>
<v-list-group
no-action
prepend-icon="account_circle"
value="true"
>
<v-list-tile slot="activator">
<v-list-tile-title>admins</v-list-tile-title>
</v-list-tile>
<v-list-tile
v-for="(admin, i) in admins"
:key="i"
#click=""
>
<v-list-tile-title v-text="admin[0]"></v-list-tile-title>
<v-list-tile-action>
<v-icon v-text="admin[1]"></v-icon>
</v-list-tile-action>
</v-list-tile>
</v-list-group>
</v-list>
</v-navigation-drawer>
<div>
<router-view></router-view>
</div>
</v-app>
</div>
</template>
<script>
export default {
data() {
return {
admins: [
['Management', 'people_outline'],
['Settings', 'settings']
]
}
}
}
</script>
./router/index.js
import Vue from 'vue'
import Router from 'vue-router'
import AppS from '#/components/SellingPage/AppS'
import sellingSummary from '#/components/SellingPage/subPage/sellingSummary'
Vue.use(Router)
export default new Router({
routes: [
{
path: '/SellingPage',
name: 'AppS',
component: AppS
},
{
path: '/SellingPage',
name: 'sellingSummary',
component: sellingSummary
}
]
})
./components/SellingPage/subPage/sellingSummary
<template>
<div>
<p>Hi, first</p>
</div>
</template>
./components/SellingPage/AppS
<template>
<div>
<app-header></app-header>
<v-card>
<app-selling>
</app-selling>
</v-card>
</div>
</template>
<script>
import Header from '../Header.vue';
import Selling from './Selling.vue';
export default {
components: {
'app-header': Header,
'app-selling': Selling
}
}
</script>
<v-navigation-drawer
disable-route-watcher
enable-resize-watcher
:clipped="clipped"
v-model="sideNav"
dark
app
>
try this
For starters, you can't have two routes in your router configured for different components. The Router will only use the first entry.
In your component Vue file add the following property in the data property
drawer: true,
Example:
export default {
data: () => ({
drawer: true
})
}
The Navigation drawer has an item data property which can be used to loop through existing menu items.
In some of the properties, you can add a path attribute directing to an existing path on the router when that menu item is pressed.
Here is an example:
https://codepen.io/wernerm/pen/rzqqbR