element table 使用<template slot=“header“>数据不渲染

文章讨论了在Vue.js应用中遇到的问题,即使用v-if和v-show指令的模板插槽在数据更新后未能正确渲染。解决方案是将slot属性改为#header的语法形式,以确保内容能根据数据变化更新。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<template slot="header">
  <span v-if="iconShow" class="required">{{ $t('rdq.developQuestionInc.effectConfirmed') }}</span>
  <span v-else>{{ $t('rdq.developQuestionInc.effectConfirmed') }}</span>
</template>

<template slot="header">里使用v-if v-show指令数据更新后不渲染

将 slot="header" 改为 #header

<template #header>
  <span v-if="iconShow" class="required">{{ $t('rdq.developQuestionInc.effectConfirmed') }}</span>
  <span v-else>{{ $t('rdq.developQuestionInc.effectConfirmed') }}</span>
</template>

<el-table :data="HeadItemData" style="width: 100%" max-height="400" >> <el-table-column label="字节序号" width="100"> <template #default="{ row }"> <span :style="{ color: row.byteNo > 32 ? 'red' : 'inherit' }"> {{ row.byteNo }} </span> </template> </el-table-column> <el-table-column label="字节数" width="100" prop="len" ></el-table-column> <el-table-column label="数据类型" width="120" prop="dataType"> <template v-slot="scope"> <!-- 数据区不选择数据类型 --> <el-select v-model="scope.row.dataType" placeholder="请选择数据类型" :disabled="scope.row.itemApp === '8'" @change="(val) => handleDataTypeChange(scope.row, val)" > <el-option label="int8" value="1"></el-option> <el-option label="uint8" value="2"></el-option> </el-select> </template ></el-table-column> <el-table-column label="范围" width="210" prop="range" ><template v-slot="scope"> <div class="range-inputs"> <el-input v-model="scope.row.startRange" " placeholder="起始值" clearable style="width: 80px" ></el-input> <span style="margin: 0 5px">-</span> <el-input v-model="scope.row.endRange" " placeholder="结束值" clearable style="width: 80px" ></el-input></div></template ></el-table-column> <el-table-column label="数据项应用类型" width="180" prop="itemApp"> <template v-slot="scope"> <el-select v-model="scope.row.itemApp" " placeholder="请选择数据项应用类型" > <el-option v-for="opt in getOptions(scope.$index)" :key="opt.value" :label="opt.label" :value="opt.value" /> </el-select> </template ></el-table-column> <el-table-column label="校验类型" width="160" prop="verifyType" ><template v-slot="scope"> <el-select v-model="scope.row.verifyType" :disabled="scope.row.itemApp !== '7'" :placeholder=" scope.row.itemApp === '7' ? '请选择校验类型' : '-' " > <el-option label="求和取模" value="0"></el-option> <el-option label="求和取低字节" value="1"></el-option> </el-select> </template ></el-table-column> <el-table-column label="默认值" width="210" prop="default" ><template #header> <div style="display: inline"> 默认值 <el-input v-model="globalDefault" placeholder="请输入默认值" @input="debouncedUpdateDefaults" /> </div> </template> <template #default="scope"> {{ scope.row.default }} </template></el-table-column > <el-table-column label="操作" width="150" fixed="right"> <template v-slot="scope" ><el-button type="text" >上移</el-button ><el-button type="text" >下移</el-button ><el-button type="text" @click="deleteItem(scope.$index)" >删除</el-button ></template > </el-table-column> </el-table>在表格倒数第二行固定添加一个按钮(此行只有行中间有个按钮“+”)
03-13
<template> <div class="label-container"> <div style="border: 1px solid #d9d9d9"></div> <div class="header"> <div class="biaoqian">客户特征标签</div> <el-popover placement="right" popper-class="group-popover" width="287" trigger="click"> <div class="full-label-section"> <span>业务需求</span> <div class="full-tag-group"> <el-popover v-for="(item, index) in requireList" :key="index" placement="top-start" popper-class="grid-popover" trigger="hover" :content="item.labelName" v-if="shouldShowPopover(item)" > <el-tag slot="reference" size="mini" class="truncate-tag" >{{ item.labelName }}</el-tag> </el-popover> <el-tag v-for="(item, index) in requireList" v-if="!shouldShowPopover(item)" :key="index" size="mini" >{{ item.labelName }}</el-tag> </div> </div> <div class="full-label-section"> <span>业务特征</span> <div class="full-tag-group"> <el-popover v-for="(item, index) in featureList" :key="index" placement="top-start" popper-class="grid-popover" trigger="hover" :content="item.labelName" v-if="shouldShowPopover(item)" > <el-tag slot="reference" type="" size="mini" class="truncate-tag" >{{ item.labelName }}</el-tag> </el-popover> <el-tag v-for="(item, index) in featureList" v-if="!shouldShowPopover(item)" :key="index" type="success" size="mini" >{{ item.labelName }}</el-tag> </div> </div> <div class="full-label-section full-label-sections"> <span>拓展任务</span> <div class="full-tag-group"> <el-popover v-for="(item, index) in taskList" :key="index" placement="top-start" popper-class="grid-popover" trigger="hover" :content="item.labelName" v-if="shouldShowPopover(item)" > <el-tag slot="reference" type="danger" size="mini" class="truncate-tag" >{{ item.labelName }}</el-tag> </el-popover> <el-tag v-for="(item, index) in taskList" v-if="!shouldShowPopover(item)" :key="index" type="danger" size="mini" >{{ item.labelName }}</el-tag> </div> </div> <el-button slot="reference" class="btn">更多</el-button> </el-popover> </div> <!-- 客户特征部分标签 --> <div style="padding: 10px; background: #fafafa"> <div class="label-section"> <span>业务需求</span> <div class="tag-group"> <el-popover v-for="(item, index) in showRequireList" :key="index" placement="top-start" popper-class="grid-popover" trigger="hover" :content="item.labelName" v-if="shouldShowPopover(item)" > <el-tag slot="reference" size="mini" class="truncate-tag" >{{ item.labelName }}</el-tag> </el-popover> <el-tag v-for="(item, index) in showRequireList" v-if="!shouldShowPopover(item)" :key="index" size="mini" >{{ item.labelName }}</el-tag> </div> </div> <div class="label-section"> <span>业务特征</span> <div class="tag-group"> <el-popover v-for="(item, index) in showFeatureList" :key="index" placement="top-start" popper-class="grid-popover" trigger="hover" :content="item.labelName" v-if="shouldShowPopover(item)" > <el-tag slot="reference" type="success" size="mini" class="truncate-tag" >{{ item.labelName }}</el-tag> </el-popover> <el-tag v-for="(item, index) in showFeatureList" v-if="!shouldShowPopover(item)" :key="index" type="success" size="mini" >{{ item.labelName }}</el-tag> </div> </div> <div class="label-section"> <span>拓展任务</span> <div class="tag-group"> <el-popover v-for="(item, index) in showTaskList" :key="index" placement="top-start" popper-class="grid-popover" trigger="hover" :content="item.labelName" v-if="shouldShowPopover(item)" > <el-tag slot="reference" type="danger" size="mini" class="truncate-tag" >{{ item.labelName }}</el-tag> </el-popover> <el-tag v-for="(item, index) in showTaskList" v-if="!shouldShowPopover(item)" :key="index" type="danger" size="mini" >{{ item.labelName }}</el-tag> </div> </div> </div> </div> </template> <script> import { Tag, Button, Popover,Tooltip } from 'element-ui'; export default { name: 'groupLabelBox', components: { [Tag.name]: Tag, [Button.name]: Button, [Popover.name]: Popover, [Tooltip.name]: Tooltip, }, props: { requireList: { type: Array, required: true, }, featureList: { type: Array, required: true, }, taskList: { type: Array, required: true, }, }, data() { return { dialogVisible: false, }; }, computed: { showRequireList() { return this.requireList.slice(0, 2); }, showFeatureList() { return this.featureList.slice(0, 2); }, showTaskList() { return this.taskList.slice(0, 2); }, }, methods: { shouldShowPopover(item) { return item?.labelName?.length >= 7 } }, }; </script> <style lang="less" scoped> .group-popover { padding: 30px !important; /* 标题样式 */ .full-label-section{ padding-bottom: 12px; > span { display: block; margin-bottom: 10px; width: 56px; height: 14px; font-family: PingFangSC, PingFang SC, sans-serif; font-weight: 400; font-size: 14px; color: #888888; line-height: 14px; text-align: left; font-style: normal; } } /* 标签组样式 */ .full-tag-group { display: flex; flex-wrap: wrap; justify-content: flex-start; gap: 6px; .el-tag { margin: 0 !important; border-radius: 4px; font-size: 12px; padding: 0 8px; height: 24px; line-height: 24px; } } .full-label-sections { padding-bottom: 0 !important; } } .truncate-tag { display: inline-block; max-width: 112px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; vertical-align: middle; cursor: default; } .truncate-tag:hover:after { position: absolute; top: 30px; left: 10px; content: attr(data-title); color: #333333; } .grid-popover { min-width: 54px; text-align: center; padding: 10px 10px; } .label-container { position: relative; padding: 0px 14px 7px 16px; } .header { display: flex; justify-content: space-between; align-items: center; margin: 10px 0px; .biaoqian { width: 84px; height: 14px; font-family: PingFangSC, PingFang SC, sans-serif; font-weight: 400; font-size: 14px; color: #888888; line-height: 14px; text-align: left; font-style: normal; } .btn { width: 33px; height: 17px; padding: 0 4px; background: #ffffff; border-radius: 2px; border: 1px solid #cbcbcb; font-weight: 400; font-size: 12px; color: #333333; line-height: 17px; font-style: normal; > span { display: block; width: fit-content; } } } .label-section { > span { display: block; margin-bottom: 5px; width: 48px; height: 14px; font-family: PingFangSC, PingFang SC, sans-serif; font-weight: 400; font-size: 12px; color: #333333; line-height: 14px; text-align: left; font-style: normal; } } .tag-group { display: flex; gap: 10px; flex-wrap: wrap; } .label-section:not(:last-child) { margin-bottom: 10px; } </style> 使用vue2+js优化简化以上代码
07-13
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

想散在风中

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值