如何让table隐藏

<!doctype html>
<html>
<head>
 <meta charset="utf-8">
 <title>如何让table隐藏</title>
 <style>
 .appad{
 width: 600px;
 height: 200px;
 background: #ddd;
 margin-top: 70px;
 border-radius: .25rem;
 display: none;
}
 .dicount{
 height: 44px;
} 
.revew{
 padding:10px 15px 0 ;
 font-weight: 400;
} 
.btndon{
 padding: 0 15px;
 
}
.vrer{
 padding: 0 5px;
 border-radius: .25rem;
 width: 85px;
}
 .scesd{
 line-height: 60px;
}
 .asred{
 width: 70px;
 height: 30px;
 border-radius: 5px;
 border: 1px solid #007bff;
 background: #007bff;
}
 </style>
</head>
<body>
 <button type="button" class="asred" id="primary">Primary</button>
  <div class="appad" id="cdmsicv">
   <div class="dicount">
    <h3 class="revew">表格</h3>
   </div>
   <div class="btndon">
    <table class="rfsad">
     <tr>
      <th>表头</th>
      <th>表头</th>
      <th>表头</th>
      <th></th>
     </tr>
     <tr>
      <td>内容一
      <select name="" class="vrer">
        <option value="">请选择</option>
        <option value="">项目一</option>
        <option value="">项目二</option>
       </select>
      </td>
      <td>内容二
      <select name="" class="vrer">
        <option value="">请选择</option>
        <option value="">项目一</option>
        <option value="">项目二</option>
       </select>
      </td>
      <td>内容三
      <select name="" class="vrer">
        <option value="">请选择</option>
        <option value="">项目一</option>
        <option value="">项目二</option>
       </select>
      </td>
      <td>内容四
      <select name="" class="vrer">
        <option value="">请选择</option>
        <option value="">项目一</option>
        <option value="">项目二</option>
       </select>
      </td>
     </tr>
    </table>
   <div class="scesd">
     <span>内容五</span>
     <input type="text">
    </div>
    <div class="wdefew">
     <button class="asred" id="ecece"></button>
    </div>
   </div>
  </div>
  
  <script>
   window.onclick=function(){
    var cdmsicv=document.getElementById("cdmsicv");
           var ecece=document.getElementById("ecece");
     primary.onclick=function(){
    cdmsicv.style.display="block";
     };
     ecece.onclick=function(){
      cdmsicv.style.display="none";
     };
    }
  </script>
</body>
</html>

### 隐藏 `el-table` 组件的方法 在 Element-UI 中,可以通过控制组件的显示状态来实现隐藏功能。具体方法是通过绑定一个布尔类型的变量到 `v-if` 或者 `v-show` 指令上。 #### 使用 `v-if` 实现隐藏 如果希望彻底移除 DOM 节点并释放资源,则可以使用 `v-if` 指令。当条件为假时,整个表格会被销毁,不再渲染到页面中。 ```vue <template> <div> <button @click="toggleTable">切换表格</button> <el-table v-if="isTableVisible" :data="tableData"> <!-- 表格列定义 --> </el-table> </div> </template> <script> export default { data() { return { isTableVisible: true, tableData: [ { name: '张三', age: 28 }, { name: '李四', age: 30 } ] }; }, methods: { toggleTable() { this.isTableVisible = !this.isTableVisible; } } }; </script> ``` 上述代码展示了如何利用 `v-if` 来动态控制表格的可见性[^1]。 #### 使用 `v-show` 实现隐藏 如果只是想简单地改变样式而不重新创建实例,则可以选择 `v-show` 指令。它会一直保持 DOM 存在并通过 CSS 的 `display` 属性控制其显隐。 ```vue <template> <div> <button @click="toggleTable">切换表格</button> <el-table v-show="isTableVisible" :data="tableData"> <!-- 表格列定义 --> </el-table> </div> </template> <script> export default { data() { return { isTableVisible: true, tableData: [ { name: '王五', age: 25 }, { name: '赵六', age: 27 } ] }; }, methods: { toggleTable() { this.isTableVisible = !this.isTableVisible; } } }; </script> ``` 此方式适用于频繁切换场景下的性能优化需求。 综上所述,在实际开发过程中可以根据项目具体情况选择适合的方式完成对 `el-table` 的隐藏操作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值