javascript - 在 V-Data-Table 中隐藏/显示多列
问题描述
我可以寻求您的帮助吗,我目前正在使用 vuetifyjs 使列显示/隐藏,我偶然发现了这些参考:
https://codepen.io/anon/pen/jeWRvN
computedHeaders () {
if(this.hideCalories){
return this.headers.filter(header => header.text !== "Calories")
}
return this.headers;
}
},
我的问题是它只能隐藏 1 个标题/列。你能帮我让它隐藏多个标题吗?我想实现这些输出:
非常感谢。
解决方案
headers
属性可以计算
computed: {
headers() {
let headers = [
{
text: 'Dessert (100g serving)',
align: 'left',
sortable: false,
value: 'name'
}
]
if (!this.hideCalories) {
headers.push({ text: 'Calories', value: 'calories' })
}
if (!this.hideFat) {
headers.push({ text: 'Fat (g)', value: 'fat' })
}
// ...
headers.push({ text: 'Carbs (g)', value: 'carbs' })
headers.push({ text: 'Protein (g)', value: 'protein' })
headers.push({ text: 'Actions', value: 'name', sortable: false })
return headers
}
}
然后像以前一样传递headers
给表。
推荐阅读
- python - 无法使用 selenium 从名为 pro 列表的下拉列表中选择 CS:GO
- firebase - 如何在 Next JS 中显示 Firebase 云通知?
- java - Java计算输入单词中辅音数量的方法
- react-native - 如何与 react-native-fbsdk GraphRequest 分享帖子
- raspberry-pi - can0 监听 can-bus 但没有数据出现
- django - 如何设置实例变量的默认值?
- python - Pandas Groupby / 多行列表
- c++ - 在 unique_ptr 向量中使用 push_back(std::move())
- vue.js - 使用部分身份框架在 ASP.NET Core 中存储用户 ID
- rendering - 在嵌入式系统中使用 bgfx 进行文本渲染时出现奇怪的线条(瑞萨 H3)