Acenollari

Forum Replies Created

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • in reply to: Can’t expand only one element on my v-data-table #122289
    Acenollari
    Participant

    Solution: Use item-value in Vuetify 3 to prevent all rows from expanding at once

    In Vuetify 3, when using <v-data-table> with expandable rows, it’s important to specify a unique identifier for each item using the item-value prop. If you don’t, Vuetify can’t properly track which row is being expanded, and as a result, all rows might expand at the same time.

    To fix this, just add:
    item-value=”menu_item_id”

    Where menu_item_id is a unique key for each row item. Here’s how it looks in context:
    <v-data-table
    item-value=”menu_item_id”
    :items=”menuSchemaCp[0]?.details”
    :headers=”menuHeaders”
    show-expand

    >
    This ensures that Vuetify correctly manages the expanded state for individual rows.
     

    Acenollari
    Participant

    Make sure to use this structure in app.vue
    <template>
    <v-app>
    <!– Your content here –>
    </v-app>
    </template>

    Acenollari
    Participant

    If an element inside a v-tabs-window-item (e.g., v-autocomplete, v-text-field, etc.) is using an incorrect or undefined variable for v-model, such as:

    <v-text-field
    label=”Mjeti”
    hide-details
    density=”compact”
    v-model=”item.transporterObj.vehicle_description”       <!– This variable might not exist –>
    single-line
    variant=”outlined”
    ></v-text-field>

    When navigating to the tab containing this element, the application may freeze if the specified variable (item.transporterObj.vehicle_description) does not exist or is undefined. This is because v-model tries to bind to a reactive property that isn’t properly initialized, causing unexpected behavior in Vue.

    Acenollari
    Participant

    Solution:

    The issue occurs due to a typo in the code. While VS Code does not highlight this as a syntax error, a closer look reveals that only one of the <v-tabs-window-item> elements is correctly used. The other elements incorrectly use the tag <v-tab-window-item>. These incorrectly used tags display their content at all times, causing the content of other tabs to appear below the first tab’s content.

    Here is the corrected code:

    <v-tabs v-model=”tab” bg-color=”#2e76bc” color=”white”>
    <v-tab v-for=”item in tabItems” :key=”item”>{{ item }}</v-tab>
    </v-tabs>

    <v-tabs-window v-model=”tab”>
    <v-tabs-window-item></v-tabs-window-item>
    <v-tabs-window-item></v-tabs-window-item>
    <v-tabs-window-item></v-tabs-window-item>
    </v-tabs-window>

    Acenollari
    Participant

    If you import watchEffect from vue and use it to check if one of the values changes, this method will check every time if the value changes, and if it does you will notice. Before i didn’t use this method the values stayed loading and not showing on my localhost.

    <template>
    <v-container>
    <v-row v-for=”category in categories”>
    <v-col>
    <v-card :key=”category.category_id” class=”mx-auto card-category” max-width=”400″>
    <v-img
    class=”align-end text-white”
    height=”200″
    :src=”category?.photos[0]?.photo_path”
    cover
    >
    <v-row class=”d-flex justify-center title-row”>
    <v-card-title class=”card-title”>{{ category.name }}</v-card-title>
    </v-row>
    </v-img>
    </v-card>
    </v-col>
    </v-row>
    </v-container>
    </template>
    <script lang=”ts”>
    import { defineComponent, ref, watchEffect } from ‘vue’
    import { useQuery } from ‘@/api/apollo/apolloClient’
    import { apolloClient } from ‘@/api/apollo/apolloClient’
    import { GET_CATEGORIES } from ‘../api/gql/queries’

    // Define the shape of the category object directly in the component
    interface Category {
    category_id: string
    code: string
    name: string
    photos: Array<any>
    }

    // Define a type/interface for the data returned by the GET_CATEGORIES query
    interface CategoryData {
    categories: Category[]
    }

    export default defineComponent({
    name: ‘CategoryList’,
    setup() {
    let categories = ref<Category[]>([])
    const { loading, error, result } = useQuery(GET_CATEGORIES)
    console.log(result.value,’=-= result value’)
    console.log(loading, result, ‘result’)
    // Ensure data is available and not loading
    if (!loading.value && result.value) {
    console.log(result.value, ‘result’)
    categories.value = result.value?.categories ?? []
    console.log(categories, ‘categorieeeeeeeees’)
    }
    watchEffect(() => {
    if (!loading.value && result.value) {
    categories.value = result.value.categories ?? []
    }
    })
    return {
    categories
    }
    }
    })
    </script>

    in reply to: Failed to resolve component: #9311
    Acenollari
    Participant

    All this errors can be erased if you make this change on main.ts

    import { createApp, h, provide, render } from ‘vue’
    import App from ‘./App.vue’
    import router from ‘./router’
    // import vuetify from ‘./plugins/vuetify’
    import ‘vuetify/styles’
    import { createVuetify } from ‘vuetify’
    import { loadFonts } from ‘./plugins/webfontloader’
    import * as components from ‘vuetify/components’
    import * as directives from ‘vuetify/directives’
    //import { apolloClient } from ‘@/api/apollo/apolloClient’
    import { ApolloClient, createHttpLink, InMemoryCache } from ‘@apollo/client/core’
    import { DefaultApolloClient } from ‘@vue/apollo-composable’
    const vuetify = createVuetify({
    components,
    directives
    })
    // HTTP connection to the API
    const httpLink = createHttpLink({
    // You should use an absolute URL here
    uri: ‘http://localhost:4000/graphql&#8217;
    })

    // Cache implementation
    const cache = new InMemoryCache()

    // Create the apollo client
    const apolloClient = new ApolloClient({
    link: httpLink,
    cache
    })

    const app = createApp({
    setup() {
    provide(DefaultApolloClient, apolloClient)
    },
    render: () => h(App)
    })

    app.use(router).use(vuetify).mount(‘#app’)

    • This reply was modified 2 years, 1 month ago by Acenollari.
    in reply to: Vuetify v-select with image #1169
    Acenollari
    Participant

    VUETIFY

    <v-select
    class=”select-style”
    :items=”items”
    id=”locale”
    @input=”switchLocale”
    v-model=”selectedLocale”
    >
    <template v-slot:selection=”{ item, index }”>

    {{ item.label }}
    </template>
    <template v-slot:item=”{ item }”>

    {{ item.label }}
    </template>
    </v-select>

     

    <span style=”text-decoration: underline;”></span>

    SCRIPT

    return {

    items: [
    { value: ‘al’, label: ‘Shqip’, image: ‘albaniaflag.png’ },
    { value: ‘en’, label: ‘English’, image: ‘gbflag.png’ },
    ],
    }

Viewing 7 posts - 1 through 7 (of 7 total)