*初级小白*~ 2022-09-05 16:41 采纳率: 97.9%
浏览 278
已结题

table表格的tr为什么不换行

为什么表格table的tr不换行

img



<template>
  <div ref="printHtml">
    <div class="wraper">
      <div>
        <thttps://img-mid.csdnimg.cn/release/static/image/mid/ask/413267863266163.png "#left")
able border="1px" cellspacing="0" cellpadding="15px">
          <thead>
            <tr>
              <th rowspan="2">1</th>
              <th rowspan="2">2</th>
              <th rowspan="2">3</th>
              <th rowspan="2">4</th>
              <th rowspan="2">5</th>
              <th rowspan="2">6</th>
              <th rowspan="2">7</th>
              <th rowspan="2">8</th>
              <th rowspan="2">9</th>
              <th rowspan="2">0</th>
              <th rowspan="2">11</th>
              <th rowspan="2">12</th>
              <th rowspan="2">13</th>
              <th rowspan="2">14</th>
              <th rowspan="2">15</th>
              <th colspan="2">16</th>
              <th rowspan="2">17</th>
              <th rowspan="2">18</th>
              <th rowspan="2">操作</th>
            </tr>
            <tr>
              <th>辅A</th>
              <th>辅B</th>
            </tr>
          </thead>
          <tbody>
            <tr v-for="(item,index) in data" :key="index">
              <td rowspan="2">{{index}}</td>
              <td rowspan="2">12</td>
              <td rowspan="2">12</td>
              <td rowspan="2">1</td>
              <td rowspan="2">2</td>
              <td rowspan="2">2</td>
              <td rowspan="2">2</td>
              <td rowspan="2">2</td>
              <td rowspan="2">3</td>
              <td rowspan="2">2</td>
              <td rowspan="2">3</td>
              <td rowspan="2">3</td>
              <td rowspan="2">3</td>
              <td rowspan="2">3</td>
              <td rowspan="2">3</td>
              <td colspan="2" rowspan="2">3</td>
              <td rowspan="2">4</td>
              <td rowspan="2">5</td>
              <td rowspan="2">6</td>
            </tr>
          </tbody>
        </table>
      </div>
    </div>
  </div>
</template>

<script>
import { reactive, ref } from "vue";

export default {
  setup() {
    const data = [
      {
        "1": 40,
        "2": 3077,
        "3": null,
        "4": null,
        "5": null,
        "6": null,
        "7": 2,
        "8": 8300,
        "9": 0,
        "10": null,
        "11": null,
        "12": null,
        "13": "PP11",
        "14": 40,
        "15": 3000,
        "16": 18,
        "17": 7,
        "18": [
          "11220303201"
        ],
        "19": [
          "SN25-ZJ-FY1-BF"
        ],
      },
      {
        "1": 40,
        "2": 3077,
        "3": null,
        "4": null,
        "5": null,
        "6": null,
        "7": 2,
        "8": 8300,
        "9": 0,
        "10": null,
        "11": null,
        "12": null,
        "13": "PP11",
        "14": 40,
        "15": 3000,
        "16": 18,
        "17": 7,
        "18": [
          "11220303201"
        ],
        "19": [
          "SN25-ZJ-FY1-BF"
        ],
      },
      {
        "1": 40,
        "2": 3077,
        "3": null,
        "4": null,
        "5": null,
        "6": null,
        "7": 2,
        "8": 8300,
        "9": 0,
        "10": null,
        "11": null,
        "12": null,
        "13": "PP11",
        "14": 40,
        "15": 3000,
        "16": 18,
        "17": 7,
        "18": [
          "11220303201"
        ],
        "19": [
          "SN25-ZJ-FY1-BF"
        ],
      },
      {
        "1": 40,
        "2": 3077,
        "3": null,
        "4": null,
        "5": null,
        "6": null,
        "7": 2,
        "8": 8300,
        "9": 0,
        "10": null,
        "11": null,
        "12": null,
        "13": "PP11",
        "14": 40,
        "15": 3000,
        "16": 18,
        "17": 7,
        "18": [
          "11220303201"
        ],
        "19": [
          "SN25-ZJ-FY1-BF"
        ],
      },
    ]
  
    return {
    
      data,
    };
  },
};
</script>

<style lang="scss" scoped>
.table {
  border: none;
  border-collapse: collapse;
  background: white;
  text-align: center;
  margin-top: 10px;

  thead {
    tr {
      color: white;
      height: 30px;

      th {
        background-color: rgba(255, 140, 45, 0.44);
        min-width: 100px;
        position: -webkit-sticky;
        position: sticky;
        top: 0;
        z-index: 3;
        border: 1px solid rgba(0, 0, 0, 0.1);
      }
    }
  }

  tbody {
    tr {
      height: 30px;
      color: black;

      td {
        border: 1px solid rgba(0, 0, 0, 0.1);
        position: -webkit-sticky;
        position: sticky;
        min-width: 100px;
      }
    }
  }
}
</style>

                 

                 

  • 写回答

7条回答 默认 最新

  • CSDN专家-showbo 2022-09-06 10:44
    关注

    v-for中rowspan="2"去掉就可以了,要不rowspan是合并行,会将不够的单元格提到上一行

     
    <template>
      <div ref="printHtml">
        <div class="wraper">
          <div>
            <table border="1px" cellspacing="0" cellpadding="15px">
              <thead>
                <tr>
                  <th rowspan="2">1</th>
                  <th rowspan="2">2</th>
                  <th rowspan="2">3</th>
                  <th rowspan="2">4</th>
                  <th rowspan="2">5</th>
                  <th rowspan="2">6</th>
                  <th rowspan="2">7</th>
                  <th rowspan="2">8</th>
                  <th rowspan="2">9</th>
                  <th rowspan="2">0</th>
                  <th rowspan="2">11</th>
                  <th rowspan="2">12</th>
                  <th rowspan="2">13</th>
                  <th rowspan="2">14</th>
                  <th rowspan="2">15</th>
                  <th colspan="2">16</th>
                  <th rowspan="2">17</th>
                  <th rowspan="2">18</th>
                  <th rowspan="2">操作</th>
                </tr>
                <tr>
                  <th>辅A</th>
                  <th>辅B</th>
                </tr>
              </thead>
              <tbody>
                <tr v-for="(item,index) in data" :key="index">
                  <td>{{index}}</td>
                  <td>12</td>
                  <td>12</td>
                  <td>1</td>
                  <td>2</td>
                  <td>2</td>
                  <td>2</td>
                  <td>2</td>
                  <td>3</td>
                  <td>2</td>
                  <td>3</td>
                  <td>3</td>
                  <td>3</td>
                  <td>3</td>
                  <td>3</td>
                  <td colspan="2">3</td>
                  <td>4</td>
                  <td>5</td>
                  <td>6</td>
                </tr>
              </tbody>
            </table>
          </div>
        </div>
      </div>
    </template>
     
    <script>
    import { reactive, ref } from "vue";
     
    export default {
      setup() {
        const data = [
          {
            "1": 40,
            "2": 3077,
            "3": null,
            "4": null,
            "5": null,
            "6": null,
            "7": 2,
            "8": 8300,
            "9": 0,
            "10": null,
            "11": null,
            "12": null,
            "13": "PP11",
            "14": 40,
            "15": 3000,
            "16": 18,
            "17": 7,
            "18": [
              "11220303201"
            ],
            "19": [
              "SN25-ZJ-FY1-BF"
            ],
          },
          {
            "1": 40,
            "2": 3077,
            "3": null,
            "4": null,
            "5": null,
            "6": null,
            "7": 2,
            "8": 8300,
            "9": 0,
            "10": null,
            "11": null,
            "12": null,
            "13": "PP11",
            "14": 40,
            "15": 3000,
            "16": 18,
            "17": 7,
            "18": [
              "11220303201"
            ],
            "19": [
              "SN25-ZJ-FY1-BF"
            ],
          },
          {
            "1": 40,
            "2": 3077,
            "3": null,
            "4": null,
            "5": null,
            "6": null,
            "7": 2,
            "8": 8300,
            "9": 0,
            "10": null,
            "11": null,
            "12": null,
            "13": "PP11",
            "14": 40,
            "15": 3000,
            "16": 18,
            "17": 7,
            "18": [
              "11220303201"
            ],
            "19": [
              "SN25-ZJ-FY1-BF"
            ],
          },
          {
            "1": 40,
            "2": 3077,
            "3": null,
            "4": null,
            "5": null,
            "6": null,
            "7": 2,
            "8": 8300,
            "9": 0,
            "10": null,
            "11": null,
            "12": null,
            "13": "PP11",
            "14": 40,
            "15": 3000,
            "16": 18,
            "17": 7,
            "18": [
              "11220303201"
            ],
            "19": [
              "SN25-ZJ-FY1-BF"
            ],
          },
        ]
      
        return {
        
          data,
        };
      },
    };
    </script>
     
    <style lang="scss" scoped>
    .table {
      border: none;
      border-collapse: collapse;
      background: white;
      text-align: center;
      margin-top: 10px;
     
      thead {
        tr {
          color: white;
          height: 30px;
     
          th {
            background-color: rgba(255, 140, 45, 0.44);
            min-width: 100px;
            position: -webkit-sticky;
            position: sticky;
            top: 0;
            z-index: 3;
            border: 1px solid rgba(0, 0, 0, 0.1);
          }
        }
      }
     
      tbody {
        tr {
          height: 30px;
          color: black;
     
          td {
            border: 1px solid rgba(0, 0, 0, 0.1);
            position: -webkit-sticky;
            position: sticky;
            min-width: 100px;
          }
        }
      }
    }
    </style>
     
                     
     
                     
    
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(6条)

报告相同问题?

问题事件

  • 系统已结题 9月14日
  • 已采纳回答 9月6日
  • 修改了问题 9月5日
  • 修改了问题 9月5日
  • 展开全部

悬赏问题

  • ¥20 CST怎么把天线放在座椅环境中并仿真
  • ¥15 任务A:大数据平台搭建(容器环境)怎么做呢?
  • ¥15 r语言神经网络自变量重要性分析
  • ¥15 基于双目测规则物体尺寸
  • ¥15 wegame打不开英雄联盟
  • ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)
  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?