Mat*_*ndo 3 datatable vue.js vue-resource vuejs2 vuetify.js
我正在尝试制作一个用 json 数据填充的 v-data-table (Vue + Vuetify + Vue-Resource)。我可以毫无问题地显示数据,但我需要更改标题的第一列以让用户实际查看的数据可见。目前我使用的是静态标头,没有我想要的标签:
headers: [
{
text: "",
align: "left",
sortable: false,
value: "name",
id: "primeiraColunaColuna"
},
{ text: "total QTD", value: "total QTD" },
{ text: "total", value: "Total" },
{ text: "Date", value: "Date" },
{ text: "Time", value: "Time" }
],
Run Code Online (Sandbox Code Playgroud)
我想让文本字段更改为 A、B、C、D 等。有什么办法可以实现这一点吗?
您可以从将文本作为参数的方法返回标头,例如您可以在循环中使用当前索引:
<v-layout>
<v-flex v-for="i in 3" xs4>
<v-data-table
:headers="getHeaders(i)"
:items="desserts"
class="elevation-1"
>
<template v-slot:items="props">
<td>{{ props.item.name }}</td>
<td class="text-xs-right">{{ props.item.calories }}</td>
<td class="text-xs-right">{{ props.item.fat }}</td>
</template>
</v-data-table>
</v-flex>
</v-layout>
methods:{
getHeaders(headingText){
return [
{
text: 'Dynamic heading no. ' +headingText,
align: 'left',
sortable: false,
value: 'name'
},
{ text: 'Calories', value: 'calories' },
{ text: 'Fat (g)', value: 'fat' }
];
}
Run Code Online (Sandbox Code Playgroud)
}
实例: https: //codepen.io/sf-steve/pen/pYgOze