Looking at the examples on this page, what is the way to apply toUpper to all header items? It looks too clumsy having to do it one-by-one (i.e. header.calories, header.fat...) and I can't figure out how a v-for can wrap around the template/v-slot element. Is the only way to use a 'div' and flex it horizontally?
<template>
<v-data-table
:headers="headers"
:items="desserts"
class="elevation-1"
>
<template v-slot:header.name="{ header }">
{{ header.text.toUpperCase() }}
</template>
</v-data-table>
</template>
<script>
export default {
data: () => ({
headers: [
{
text: 'Dessert (100g serving)',
align: 'start',
value: 'name',
},
{ text: 'Calories', value: 'calories' },
{ text: 'Fat (g)', value: 'fat' },
{ text: 'Carbs (g)', value: 'carbs' },
{ text: 'Protein (g)', value: 'protein' },
{ text: 'Iron (%)', value: 'iron' },
],
desserts: [
{
name: 'Frozen Yogurt',
calories: 159,
fat: 6.0,
carbs: 24,
protein: 4.0,
iron: '1%',
},
....// rest of it
],
}),
}
</script>
It is possible to loop the headers to make all capitalize
here is the working codepen: https://codepen.io/chansv/pen/gOaRWQb?editors=1010
<div id="app">
<v-app id="inspire">
<v-data-table
:headers="headers"
:items="desserts"
class="elevation-1"
hide-default-header
>
<template v-slot:header="{ props }">
<th v-for="head in props.headers">{{ head.text.toUpperCase() }}
</template>
</v-data-table>
</v-app>
</div>
new Vue({
el: '#app',
vuetify: new Vuetify(),
data: () => ({
headers: [
{
text: 'Dessert (100g serving)',
align: 'start',
value: 'name',
},
{ text: 'Calories', value: 'calories' },
{ text: 'Fat (g)', value: 'fat' },
{ text: 'Carbs (g)', value: 'carbs' },
{ text: 'Protein (g)', value: 'protein' },
{ text: 'Iron (%)', value: 'iron' },
],
desserts: [
{
name: 'Frozen Yogurt',
calories: 159,
fat: 6.0,
carbs: 24,
protein: 4.0,
iron: '1%',
},
{
name: 'Ice cream sandwich',
calories: 237,
fat: 9.0,
carbs: 37,
protein: 4.3,
iron: '1%',
},
{
name: 'Eclair',
calories: 262,
fat: 16.0,
carbs: 23,
protein: 6.0,
iron: '7%',
},
{
name: 'Cupcake',
calories: 305,
fat: 3.7,
carbs: 67,
protein: 4.3,
iron: '8%',
},
{
name: 'Gingerbread',
calories: 356,
fat: 16.0,
carbs: 49,
protein: 3.9,
iron: '16%',
},
{
name: 'Jelly bean',
calories: 375,
fat: 0.0,
carbs: 94,
protein: 0.0,
iron: '0%',
},
{
name: 'Lollipop',
calories: 392,
fat: 0.2,
carbs: 98,
protein: 0,
iron: '2%',
},
{
name: 'Honeycomb',
calories: 408,
fat: 3.2,
carbs: 87,
protein: 6.5,
iron: '45%',
},
{
name: 'Donut',
calories: 452,
fat: 25.0,
carbs: 51,
protein: 4.9,
iron: '22%',
},
{
name: 'KitKat',
calories: 518,
fat: 26.0,
carbs: 65,
protein: 7,
iron: '6%',
},
],
}),
})
The easiest thing would just be to use custom CSS on your component. In the <style> section add:
<style>
.v-data-table-header th {
text-transform: uppercase;
}
</style>
However, if you need to do more extensive customization on the headers, you can replace the entire header row like this:
<v-data-table
:headers="headers"
hide-default-header
>
<template #header="{ props: { headers } }">
<thead class="v-data-table-header">
<tr>
<th
v-for="header in headers"
:key="header.value"
class="text-uppercase"
scope="col"
>
{{ header.text }}
</th>
</tr>
</thead>
</template>
</v-data-table>
BUT, I would discourage this because you'll lose the built-in sorting functionality that Vuetify provides. That said, you CAN use this to add an additional header row that will appear before the default one. Just leave off the hide-default-header attribute on the v-data-table component and you will get two header rows, one with all of Vuetify's default functionality plus another custom one of your own design.
your code is correct but in this form you need to add each header alone like this:
<template>
<v-data-table
:headers="headers"
:items="desserts"
class="elevation-1"
>
<template v-slot:header.name="{ header }">
{{ header.text.toUpperCase() }}
</template>
<template v-slot:header.calories="{ header }">
{{ header.text.toUpperCase() }}
</template>
...
</v-data-table>
</template>
<script>
export default {
data: () => ({
headers: [
{
text: 'Dessert (100g serving)',
align: 'start',
value: 'name',
},
{ text: 'Calories', value: 'calories' },
{ text: 'Fat (g)', value: 'fat' },
{ text: 'Carbs (g)', value: 'carbs' },
{ text: 'Protein (g)', value: 'protein' },
{ text: 'Iron (%)', value: 'iron' },
],
desserts: [
{
name: 'Frozen Yogurt',
calories: 159,
fat: 6.0,
carbs: 24,
protein: 4.0,
iron: '1%',
},
....// rest of it
],
}),
}
</script>
this way you need to do this to every header alone the way of doing it is by adding v-slot:header.<value from headers array in the data>
example:
headers = [
{
text: "text1",
...
value: "category"
}
]
code will be:
<template v-slot:header.category="{ header }">
{{ header.text.toUpperCase() }}
</template>
First answer is correct, But I want to suggest a little improvement so you don't have to style it manually.
<template v-slot:header="{ props }">
<thead class="v-data-table-header">
<tr>
<th v-for="header in props.headers" :key="header.text">{{ header.text }} </th>
</tr>
</thead>
</template>
Related
I have been using Vuetify CRUD example from https://vuetifyjs.com/en/components/data-tables/#crud-actions.
I want to add a a unique id for each record. I have taken their original code pen and copied it importing uuid library here. A sample of js is below.
https://codepen.io/joomkit/pen/MWExOGK?editors=1011
import * as uuid from "https://cdn.skypack.dev/uuid#8.3.2";
console.log(uuid.v4())
new Vue({
el: '#app',
vuetify: new Vuetify(),
data: () => ({
dialog: false,
dialogDelete: false,
headers: [
{id: 'ID', value: 'id'},
{
text: 'Dessert (100g serving)',
sortable: false,
value: 'name',
},
{ text: 'Calories', value: 'calories' },
{ text: 'Fat (g)', value: 'fat' },
{ text: 'Carbs (g)', value: 'carbs' },
{ text: 'Protein (g)', value: 'protein' },
{ text: 'Actions', value: 'actions', sortable: false },
],
desserts: [],
editedIndex: -1,
editedItem: {
id: uuid.v4(),
name: '',
calories: 0,
fat: 0,
carbs: 0,
protein: 0,
},
defaultItem: {
id: uuid.v4(),
name: '',
calories: 0,
fat: 0,
carbs: 0,
protein: 0,
},
}),
computed: {
formTitle () {
return this.editedIndex === -1 ? 'New Item' : 'Edit Item'
},
},
watch: {
dialog (val) {
val || this.close()
},
dialogDelete (val) {
val || this.closeDelete()
},
},
created () {
this.initialize()
},
methods: {
initialize () {
this.desserts = [
{
id: '1',
name: 'SFrozen Yogurt',
calories: 159,
fat: 6.0,
carbs: 24,
protein: 4.0,
},
{
id: '2',
name: 'Ice cream sandwich',
calories: 237,
fat: 9.0,
carbs: 37,
protein: 4.3,
},
{
id: '3',
name: 'Eclair',
calories: 262,
fat: 16.0,
carbs: 23,
protein: 6.0,
},
]
},
editItem (item) {
this.editedIndex = this.desserts.indexOf(item)
this.editedItem = Object.assign({}, item)
this.dialog = true
},
deleteItem (item) {
this.editedIndex = this.desserts.indexOf(item)
this.editedItem = Object.assign({}, item)
this.dialogDelete = true
},
deleteItemConfirm () {
this.desserts.splice(this.editedIndex, 1)
this.closeDelete()
},
close () {
this.dialog = false
this.$nextTick(() => {
this.editedItem = Object.assign({}, this.defaultItem)
this.editedIndex = -1
})
},
closeDelete () {
this.dialogDelete = false
this.$nextTick(() => {
this.editedItem = Object.assign({}, this.defaultItem)
this.editedIndex = -1
})
},
save () {
if (this.editedIndex > -1) {
Object.assign(this.desserts[this.editedIndex], this.editedItem)
} else {
this.desserts.push(this.editedItem)
}
this.close()
},
},
})
When i add new item in the modal dialog a new uuid is created for the added row.
However if you add more than 2 new items then the uuid is duplicated.
Is there something wrong with the inbuilt data table index here?
When start the page, uuid is assigned to "editedItem" and "defaultItem" and is not calling again.
save () {
if (this.editedIndex > -1) {
Object.assign(this.desserts[this.editedIndex], this.editedItem)
} else {
this.desserts.push(this.editedItem)
this.defaultItem.id = uuid.v4();
}
this.close()
},
If modified as above, the uuid of the next item will be newly set when the new item is saved.
And there is one other problem with the code.
When a pop-up is closed without saving by calling "NEW ITEM" for the first time, the uuid of "editedItem" in the close() function is overwritten as uuid of "defaultItem".
Set the uuid of "defaultItem" and "editedItem" to the same value.
I am trying to insert input on data-table's all th element.
<v-data-table :headers="headers" :items="desserts" item-key="name" show-select>
<template v-slot:header>
<v-text-field hide-details="auto" flat solo class="float-input"></v-text-field>
</template>
</v-data-table>
This is not working. How do I fix the code? Please help.
You above code is working, you can debug in developers console, the
component is placed next to the headers row but only in the first column, to view your input filed
you can add a label attribute to input field
If you want to add text field to each header, then you need to include props.headers and loop in header slot
Please find the below code:
<div id="app">
<v-app id="inspire">
<v-data-table :headers="headers" :items="desserts" item-key="name" show-select>
<template v-slot:header>
<v-text-field hide-details="auto" flat solo class="float-input" label="some input field in header slot"></v-text-field>
</template>
</v-data-table>
</v-app>
</div>
new Vue({
el: '#app',
vuetify: new Vuetify(),
data () {
return {
headers: [
{
text: 'Dessert (100g serving)',
align: 'start',
sortable: false,
value: 'name',
},
{ text: 'Calories', value: 'calories' },
{ text: 'Fat (g)', value: 'fat' },
{ text: 'Carbs (g)', value: 'carbs' },
{ text: 'Protein (g)', value: 'protein' },
{ text: 'Iron (%)', value: 'iron' },
],
desserts: [
{
name: 'Frozen Yogurt',
calories: 159,
fat: 6.0,
carbs: 24,
protein: 4.0,
iron: '1%',
},
{
name: 'Ice cream sandwich',
calories: 237,
fat: 9.0,
carbs: 37,
protein: 4.3,
iron: '1%',
},
{
name: 'Eclair',
calories: 262,
fat: 16.0,
carbs: 23,
protein: 6.0,
iron: '7%',
},
{
name: 'Cupcake',
calories: 305,
fat: 3.7,
carbs: 67,
protein: 4.3,
iron: '8%',
},
{
name: 'Gingerbread',
calories: 356,
fat: 16.0,
carbs: 49,
protein: 3.9,
iron: '16%',
},
{
name: 'Jelly bean',
calories: 375,
fat: 0.0,
carbs: 94,
protein: 0.0,
iron: '0%',
},
{
name: 'Lollipop',
calories: 392,
fat: 0.2,
carbs: 98,
protein: 0,
iron: '2%',
},
{
name: 'Honeycomb',
calories: 408,
fat: 3.2,
carbs: 87,
protein: 6.5,
iron: '45%',
},
{
name: 'Donut',
calories: 452,
fat: 25.0,
carbs: 51,
protein: 4.9,
iron: '22%',
},
{
name: 'KitKat',
calories: 518,
fat: 26.0,
carbs: 65,
protein: 7,
iron: '6%',
},
],
}
},
})
Please find the working codepen here: https://codepen.io/chansv/pen/BapLMyV?editors=1010
how can I embed a v-tree-view component in v-data-table ?
I have tried so many times but without any result .
with no vuetify v-tree-table forexample , here comes the question , how to integrate the v-tree-view with v-data-table ?
You can define a slot to customize any column. So there you can insert your treeview. An example:
<template>
<v-data-table
:headers="headers"
:items="cosas"
>
<template v-slot:[`item.description`]>
<td>
<template>
<v-treeview :items="treeItems"></v-treeview>
</template>
</td>
</template>
</v-data-table>
</template>
<script>
export default {
name: 'MyComponent',
data () {
return {
headers:[
{ text: 'Name', value: 'name'},
{ text: 'Description', value: 'description'},
],
cosas:[
{ name: 'Item1', description: 'description1'},
{ name: 'Item2', description: 'description2'},
],
treeItems: [
{
id: 1,
name: 'Applications :',
children: [
{ id: 2, name: 'Calendar : app' },
{ id: 3, name: 'Chrome : app' },
{ id: 4, name: 'Webstorm : app' },
],
},
{
id: 5,
name: 'Documents :',
children: [
{
id: 6,
name: 'vuetify :',
children: [
{
id: 7,
name: 'src :',
children: [
{ id: 8, name: 'index : ts' },
{ id: 9, name: 'bootstrap : ts' },
],
},
],
},
{
id: 10,
name: 'material2 :',
children: [
{
id: 11,
name: 'src :',
children: [
{ id: 12, name: 'v-btn : ts' },
{ id: 13, name: 'v-card : ts' },
{ id: 14, name: 'v-window : ts' },
],
},
],
},
],
},
{
id: 15,
name: 'Downloads :',
children: [
{ id: 16, name: 'October : pdf' },
{ id: 17, name: 'November : pdf' },
{ id: 18, name: 'Tutorial : html' },
],
},
{
id: 19,
name: 'Videos :',
children: [
{
id: 20,
name: 'Tutorials :',
children: [
{ id: 21, name: 'Basic layouts : mp4' },
{ id: 22, name: 'Advanced techniques : mp4' },
{ id: 23, name: 'All about app : dir' },
],
},
{ id: 24, name: 'Intro : mov' },
{ id: 25, name: 'Conference introduction : avi' },
],
},
],
}
}
}
</script>
Set your filters in the template to insert it only in those cells that you need it.
i try with many libraries but i feel very hard dificult, because i want to use crud in nodes child, i created solucion: i used a table of type expanded and this expended area insert other table for child. you can read in official page about expand table:
https://vuetifyjs.com/en/components/data-tables/#expandable-rows
my code:
<v-data-table
item-key="_id"
:headers="headers"
:items="items"
:single-expand="singleExpand"
:expanded.sync="expanded"
show-expand
height="670"
fixed-header
sort-by="_id"
class="elevation-1 mt-sm-5 mt-md-5 mt-lg-5 mt-xl-5"
>
<template v-slot:expanded-item="{ headers, item }">
<td :colspan="headers.length" style="background-color:#C0D0D0">
<v-card class="mx-auto my-1" max-width="900" outlined>
<v-card-text>
<div>
<span><strong> Delivery {{item.name_driver}}</strong></span>
</div>
<v-divider></v-divider>
<div>
<v-data-table
:headers="headersChild"
:items="item.children"
:items-per-page="5"
class="elevation-1"
>
</v-data-table>
</div>
</v-card-text>
</v-card>
</td>
</template>
</v-data-table>
I'm using Vuetify's v-data-tables with expandable rows. The expandable rows work fine when there's only one v-data-table on the page. When I have multiple v-data-tables, the expandable rows no longer function. I'm assuming I'm missing something that would make each data table or slot unique?
CodePen: https://codepen.io/tapal/pen/poyOdBw (this is essentially the expandable rows CodePen from Vuetify's documentation but split into two tables).
new Vue({
el: '#app',
vuetify: new Vuetify(),
data() {
return {
expanded: [],
singleExpand: false,
headers: [{
text: 'Dessert (100g serving)',
align: 'start',
sortable: false,
value: 'name',
},
{
text: 'Calories',
value: 'calories'
},
{
text: 'Fat (g)',
value: 'fat'
},
{
text: 'Carbs (g)',
value: 'carbs'
},
{
text: 'Protein (g)',
value: 'protein'
},
{
text: 'Iron (%)',
value: 'iron'
},
{
text: '',
value: 'data-table-expand'
},
],
firstDessert: [{
name: 'Frozen Yogurt',
calories: 159,
fat: 6.0,
carbs: 24,
protein: 4.0,
iron: '1%',
},
{
name: 'Ice cream sandwich',
calories: 237,
fat: 9.0,
carbs: 37,
protein: 4.3,
iron: '1%',
},
{
name: 'Eclair',
calories: 262,
fat: 16.0,
carbs: 23,
protein: 6.0,
iron: '7%',
},
{
name: 'Cupcake',
calories: 305,
fat: 3.7,
carbs: 67,
protein: 4.3,
iron: '8%',
},
{
name: 'Gingerbread',
calories: 356,
fat: 16.0,
carbs: 49,
protein: 3.9,
iron: '16%',
},
],
secondDessert: [{
name: 'Jelly bean',
calories: 375,
fat: 0.0,
carbs: 94,
protein: 0.0,
iron: '0%',
},
{
name: 'Lollipop',
calories: 392,
fat: 0.2,
carbs: 98,
protein: 0,
iron: '2%',
},
{
name: 'Honeycomb',
calories: 408,
fat: 3.2,
carbs: 87,
protein: 6.5,
iron: '45%',
},
{
name: 'Donut',
calories: 452,
fat: 25.0,
carbs: 51,
protein: 4.9,
iron: '22%',
},
{
name: 'KitKat',
calories: 518,
fat: 26.0,
carbs: 65,
protein: 7,
iron: '6%',
},
],
}
},
})
<link href="https://cdn.jsdelivr.net/npm/vuetify#2.3.10/dist/vuetify.min.css" rel="stylesheet"/>
<script src="https://cdn.jsdelivr.net/npm/vue#2.x/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vuetify#2.3.10/dist/vuetify.min.js"></script>
<div id="app">
<v-app id="inspire">
<v-data-table :headers="headers" :items="firstDessert" :single-expand="singleExpand" :expanded.sync="expanded" item-key="name" show-expand class="elevation-1">
<template v-slot:top>
<v-toolbar flat>
<v-toolbar-title>First Dessert</v-toolbar-title>
<v-spacer></v-spacer>
<v-switch v-model="singleExpand" label="Single expand" class="mt-2"></v-switch>
</v-toolbar>
</template>
<template v-slot:expanded-item="{ headers, item }">
<td :colspan="headers.length">More info about {{ item.name }}</td>
</template>
</v-data-table>
<hr />
<v-data-table :headers="headers" :items="secondDessert" :single-expand="singleExpand" :expanded.sync="expanded" item-key="name" show-expand class="elevation-1">
<template v-slot:top>
<v-toolbar flat>
<v-toolbar-title>Second Dessert</v-toolbar-title>
<v-spacer></v-spacer>
<v-switch v-model="singleExpand" label="Single expand" class="mt-2"></v-switch>
</v-toolbar>
</template>
<template v-slot:expanded-item="{ headers, item }">
<td :colspan="headers.length">More info about {{ item.name }}</td>
</template>
</v-data-table>
</v-app>
</div>
I want to programatically control the selected items in a v-data-table.
I am trying to do this by pushing items onto and splicing items out of the selected variable that I passed to v-data-table's v-model.
This example works far better in a codepen:
https://codepen.io/masonk-the-decoder/pen/OJPdmaq?editable=true&editors=101
<div id="app">
<v-app id="inspire">
<v-data-table
v-model="selected"
:headers="headers"
:items="desserts"
:single-select="singleSelect"
item-key="name"
show-select
class="elevation-1"
>
<template v-slot:top>
<v-switch v-model="singleSelect" label="Single select" class="pa-3"></v-switch>
</template>
</v-data-table>
<v-btn #click="clearSelection">Clear Selection</v-btn>
<v-btn #click="random">Select Random</v-btn>
</v-app>
</div>
const selected = [];
const desserts = [
{
name: 'Frozen Yogurt',
calories: 159,
fat: 6.0,
carbs: 24,
protein: 4.0,
iron: '1%',
},
{
name: 'Ice cream sandwich',
calories: 237,
fat: 9.0,
carbs: 37,
protein: 4.3,
iron: '1%',
},
{
name: 'Eclair',
calories: 262,
fat: 16.0,
carbs: 23,
protein: 6.0,
iron: '7%',
},
{
name: 'Cupcake',
calories: 305,
fat: 3.7,
carbs: 67,
protein: 4.3,
iron: '8%',
},
{
name: 'Gingerbread',
calories: 356,
fat: 16.0,
carbs: 49,
protein: 3.9,
iron: '16%',
},
{
name: 'Jelly bean',
calories: 375,
fat: 0.0,
carbs: 94,
protein: 0.0,
iron: '0%',
},
{
name: 'Lollipop',
calories: 392,
fat: 0.2,
carbs: 98,
protein: 0,
iron: '2%',
},
{
name: 'Honeycomb',
calories: 408,
fat: 3.2,
carbs: 87,
protein: 6.5,
iron: '45%',
},
{
name: 'Donut',
calories: 452,
fat: 25.0,
carbs: 51,
protein: 4.9,
iron: '22%',
},
{
name: 'KitKat',
calories: 518,
fat: 26.0,
carbs: 65,
protein: 7,
iron: '6%',
},
];
new Vue({
el: '#app',
vuetify: new Vuetify(),
watch: {
selected: (val) => console.log("selected watch: ", val),
},
data () {
return {
singleSelect: false,
selected,
desserts,
random() {
const idx = Math.floor(Math.random() * desserts.length);
selected.push(desserts[idx]);
console.log("Pushed: ", idx, desserts[idx]);
},
clearSelection() {
selected.splice(0, selected.length);
},
headers: [
{
text: 'Dessert (100g serving)',
align: 'left',
sortable: false,
value: 'name',
},
{ text: 'Calories', value: 'calories' },
{ text: 'Fat (g)', value: 'fat' },
{ text: 'Carbs (g)', value: 'carbs' },
{ text: 'Protein (g)', value: 'protein' },
{ text: 'Iron (%)', value: 'iron' },
],
}
},
})
What I've found is that when I press "select random" the first time, causing select.push to be called, it succeeds at changing the selection. But push the button again and nothing happens.
clearSelection never works.
Clicking to select always works.
Edit: Moving the handlers to methods makes it work. But, I don't understand why having the handlers in data broke anything. Closures are just bits of data themselves, so what's happening here?
(Codepen: https://codepen.io/masonk-the-decoder/pen/MWYLoyp)
const selected = [];
const desserts = [
{
name: 'Frozen Yogurt',
calories: 159,
fat: 6.0,
carbs: 24,
protein: 4.0,
iron: '1%',
},
{
name: 'Ice cream sandwich',
calories: 237,
fat: 9.0,
carbs: 37,
protein: 4.3,
iron: '1%',
},
{
name: 'Eclair',
calories: 262,
fat: 16.0,
carbs: 23,
protein: 6.0,
iron: '7%',
},
{
name: 'Cupcake',
calories: 305,
fat: 3.7,
carbs: 67,
protein: 4.3,
iron: '8%',
},
{
name: 'Gingerbread',
calories: 356,
fat: 16.0,
carbs: 49,
protein: 3.9,
iron: '16%',
},
{
name: 'Jelly bean',
calories: 375,
fat: 0.0,
carbs: 94,
protein: 0.0,
iron: '0%',
},
{
name: 'Lollipop',
calories: 392,
fat: 0.2,
carbs: 98,
protein: 0,
iron: '2%',
},
{
name: 'Honeycomb',
calories: 408,
fat: 3.2,
carbs: 87,
protein: 6.5,
iron: '45%',
},
{
name: 'Donut',
calories: 452,
fat: 25.0,
carbs: 51,
protein: 4.9,
iron: '22%',
},
{
name: 'KitKat',
calories: 518,
fat: 26.0,
carbs: 65,
protein: 7,
iron: '6%',
},
];
new Vue({
el: '#app',
vuetify: new Vuetify(),
watch: {
selected: (val) => console.log(val),
},
methods: {
random() {
const idx = Math.floor(Math.random() * desserts.length);
this.selected.push(desserts[idx]);
console.log("Pushed ", idx, desserts[idx]);
},
clearSelection() {
console.log(this.selected.length);
this.selected.splice(0, this.selected.length);
},
},
data () {
return {
singleSelect: false,
selected,
desserts,
headers: [
{
text: 'Dessert (100g serving)',
align: 'left',
sortable: false,
value: 'name',
},
{ text: 'Calories', value: 'calories' },
{ text: 'Fat (g)', value: 'fat' },
{ text: 'Carbs (g)', value: 'carbs' },
{ text: 'Protein (g)', value: 'protein' },
{ text: 'Iron (%)', value: 'iron' },
],
}
},
})
You can't refer to other data properties inside the data property. Also, why have you initialized both the selected array and the desserts array outside of the Vue instance? selected/deserts should be initialized inside the data property.