最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Vuejs & Vuetify : Is there a way to loop around template with datatable from vuetify (with v-slot dynamic)?

programmeradmin2浏览0评论

I have several datatable with server-side pagination, search fields and filterable fields

However, I would like to be able to generate a ponent and use the props to avoid modifying the same thing three times

Is there a way to loop around template with datatable from vuetify (with v-slot dynamic) ?

for example :

        
<template v-slot:header.id="{ header }">
    <div class="pointer border-right pa-2">
        <span class="title" @click.prevent="sortBy('id')">
            ID
            <v-icon class="ml-2">{{icon.id}}</v-icon>
        </span>
        <v-text-field v-model="searcher.ticket_id.value" type="text"
                label="Rechercher..."></v-text-field>
    </div>
</template>


<template v-slot:header.name="{ header }">
    <div class="pointer border-right pa-2">
        <span class="title" @click.prevent="sortBy('name')">
            Nom du ticket
            <v-icon class="ml-2">{{icon.name}}</v-icon>
        </span>
        <v-text-field v-model="searcher.ticket_name.value" type="text"
                label="Rechercher..."></v-text-field>
    </div>
</template>

Bee (not functional) :

<template v-for="(item, i) in headers" v-slot:item.text="{ header }">
    <div class="pointer border-right pa-2">
        <span class="title" @click.prevent="sortBy(item.name)">
            {{item.name}}
            <v-icon class="ml-2">{{icon[item.name]}}</v-icon>
        </span>
        <v-text-field v-model="item.searcher" type="text"
                label="Rechercher..."></v-text-field>
    </div>
</template>

If i add the key , i have '<template>' cannot be keyed. Place the key on real elements instead

and if i remove this i have Elements in iteration expect to have 'v-bind:key' directives

However I came across several sources that demonstrate the opposite

.html#v-for-on-a-lt-template-gt

Fix: require-v-for-key shouldn't be raised on slots

vue-language-server : Elements in iteration expect to have 'v-bind:key' directives

Thank you

Edit 20/12 :

How can I make the v-slot attribute dynamically with the vuetify data table ?

Here is my code :

<template v-for="(head, i) in headers" v-slot:header[header.value]="{header}">
    <div :key="i" class="pointer border-right pa-2">
        <span class="title" @click.prevent="sortBy('id')">
            {{head}} <br> {{header}}
            <v-icon class="ml-2">{{icon.id}}</v-icon>
        </span>
        <v-text-field v-model="searcher.ticket_id.value" type="text"
                label="Rechercher..."></v-text-field>
    </div>
</template>

It cannot be mounted on the table column

I need to use v-slot:header.id="{header}" for the mounted on the id column but I have to make id dynamic according to my loop

how to do ?

Thank you

I find it

I added head: 'header.id' in my list so i can use <template v-for="(head, i) in headers" v-slot:[headers[i].head]="{header}">

I have several datatable with server-side pagination, search fields and filterable fields

However, I would like to be able to generate a ponent and use the props to avoid modifying the same thing three times

Is there a way to loop around template with datatable from vuetify (with v-slot dynamic) ?

for example :

        
<template v-slot:header.id="{ header }">
    <div class="pointer border-right pa-2">
        <span class="title" @click.prevent="sortBy('id')">
            ID
            <v-icon class="ml-2">{{icon.id}}</v-icon>
        </span>
        <v-text-field v-model="searcher.ticket_id.value" type="text"
                label="Rechercher..."></v-text-field>
    </div>
</template>


<template v-slot:header.name="{ header }">
    <div class="pointer border-right pa-2">
        <span class="title" @click.prevent="sortBy('name')">
            Nom du ticket
            <v-icon class="ml-2">{{icon.name}}</v-icon>
        </span>
        <v-text-field v-model="searcher.ticket_name.value" type="text"
                label="Rechercher..."></v-text-field>
    </div>
</template>

Bee (not functional) :

<template v-for="(item, i) in headers" v-slot:item.text="{ header }">
    <div class="pointer border-right pa-2">
        <span class="title" @click.prevent="sortBy(item.name)">
            {{item.name}}
            <v-icon class="ml-2">{{icon[item.name]}}</v-icon>
        </span>
        <v-text-field v-model="item.searcher" type="text"
                label="Rechercher..."></v-text-field>
    </div>
</template>

If i add the key , i have '<template>' cannot be keyed. Place the key on real elements instead

and if i remove this i have Elements in iteration expect to have 'v-bind:key' directives

However I came across several sources that demonstrate the opposite

https://v2.vuejs/v2/guide/list.html#v-for-on-a-lt-template-gt

Fix: require-v-for-key shouldn't be raised on slots

vue-language-server : Elements in iteration expect to have 'v-bind:key' directives

Thank you

Edit 20/12 :

https://github./vuejs/eslint-plugin-vue/issues/1006

How can I make the v-slot attribute dynamically with the vuetify data table ?

Here is my code :

<template v-for="(head, i) in headers" v-slot:header[header.value]="{header}">
    <div :key="i" class="pointer border-right pa-2">
        <span class="title" @click.prevent="sortBy('id')">
            {{head}} <br> {{header}}
            <v-icon class="ml-2">{{icon.id}}</v-icon>
        </span>
        <v-text-field v-model="searcher.ticket_id.value" type="text"
                label="Rechercher..."></v-text-field>
    </div>
</template>

It cannot be mounted on the table column

I need to use v-slot:header.id="{header}" for the mounted on the id column but I have to make id dynamic according to my loop

how to do ?

Thank you

I find it

I added head: 'header.id' in my list so i can use <template v-for="(head, i) in headers" v-slot:[headers[i].head]="{header}">

Share Improve this question edited Jul 14, 2022 at 2:14 tony19 139k23 gold badges277 silver badges347 bronze badges asked Dec 19, 2019 at 16:47 Alexis GatuingtAlexis Gatuingt 5471 gold badge7 silver badges21 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

I had to do

<template v-for="(col, i) in filters" v-slot:[`header.${i}`]="{ header }">

in my case

filters: { 'name': [], 'calories': [] },
发布评论

评论列表(0)

  1. 暂无评论