Vue.js - element-ui el-table v-for lost the last item(Vue.js - element-ui el-table v-for 丢失最后一项)
问题描述
我想通过标题列表生成分组表头,但是 v-for 循环丢失了最后一项.
I want to generate grouping table head by a title list , but the v-for loop lost the last one item.
html模板代码:
<div id="app">
<el-table :data="tableData" stripe highlight-current-row height="100%">
<template v-for="title in titles">
<el-table-column v-if="typeof title === 'object'" :key="title" fixed :prop="Object.entries(title)[0][0]"
:label="Object.entries(title)[0][0]">
<el-table-column v-for="subtitle in Object.entries(title)[0][1]" :key="subtitle" fixed :prop="subtitle"
:label="subtitle">
</el-table-column>
</el-table-column>
<el-table-column v-else :key="title" fixed :prop="title" :label="title">
</el-table-column>
</template>
</el-table>
</div>
JavaScript 代码:
The JavaScript code:
new Vue({
el: "#app",
data() {
return {
titles: [
"title 1",
{ "title 2": ["title 2-1", "title 2-2"] },
"title 3",
"title 4"
]
};
}
});
渲染结果如下图:
我的问题是最后一项标题 4"没有显示,只剩下一个空白,希望有人能帮助我.
My problem is that the last item "title 4" is not displayed, only a blank is left, hope someone can help me.
element-ui的table doc是这里,演示代码在这里.
The table doc of element-ui is here, and the demo code is here.
推荐答案
经过一些调试我发现 fixed
prop 将 is-hidden
类添加到 th
元素隐藏 title4
并且不隐藏其他元素(我不明白为什么会发生这种情况!),为了解决这个问题,我试图移除 fixed
属性并反转条件渲染:
After some debugging i found that fixed
prop adds is-hidden
class to th
element which hide the title4
and doesn't hide the other ones (i don't understand why this is happening !!), to solve this i tried to remove the fixed
attribute and reverse the conditional rendering :
<el-table :data="tableData" stripe highlight-current-row height="100%">
<template v-for="(title,index) in titles">
<el-table-column v-if="typeof title !== 'object'" :key="title" :prop="title" :label="title">
</el-table-column>
<template v-else>
<el-table-column :prop="Object.entries(title)[0][0]" :label="Object.entries(title)[0][0]">
<el-table-column v-for="subtitle in Object.entries(title)[0][1]" :key="subtitle" fixed :prop="subtitle" :label="subtitle">
</el-table-column>
</el-table-column>
</template>
</template>
</el-table>
演示
这篇关于Vue.js - element-ui el-table v-for 丢失最后一项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Vue.js - element-ui el-table v-for 丢失最后一项
基础教程推荐
- 有没有办法使用OpenLayers更改OpenStreetMap中某些要素 2022-09-06
- 在for循环中使用setTimeout 2022-01-01
- 在 JS 中获取客户端时区(不是 GMT 偏移量) 2022-01-01
- 响应更改 div 大小保持纵横比 2022-01-01
- Karma-Jasmine:如何正确监视 Modal? 2022-01-01
- 我什么时候应该在导入时使用方括号 2022-01-01
- 角度Apollo设置WatchQuery结果为可用变量 2022-01-01
- 动态更新多个选择框 2022-01-01
- 悬停时滑动输入并停留几秒钟 2022-01-01
- 当用户滚动离开时如何暂停 youtube 嵌入 2022-01-01