Vuetify.js 数据表固定标题通过 CSS 滚动

rus*_*tyx 3 html javascript css vue.js vuetify.js

Vuetify的v-data-table部件具有fixed-header的功能,这使得头部粘在height小于工作台高度。

height明确设置时它正在工作。

HTML:

    <v-content id="mycontent">
      <v-container fluid id="mycontainer">
        <h2>Header</h2>
        <div id="outer">
          <v-data-table id="mytable" :headers="headers" :items="items" :height="height"
                        fixed-header disable-pagination disable-sort hide-default-footer>
          </v-data-table>
        </div>
      </v-container>
    </v-content>
Run Code Online (Sandbox Code Playgroud)

CSS:

#mycontent {
}
#mycontainer {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#outer {
  flex: 1;
}
#mytable {
}
#mytable table {
  width: auto;
}
Run Code Online (Sandbox Code Playgroud)

JS:

  data: () => ({
    headers: [
      { text: "Header A", value: "a" },
      { text: "Header B, longer", value: "b" },
      { text: "Header C", value: "c" }
    ],
    height: 100
  }),
  computed: {
    items() {
      var items = [];
      for (var i = 1; i <= 50; i++) {
        items.push({ a: "Row " + i, b: "Column B", c: "Column C" });
      }
      return items;
    }
  },
  methods: {
    onResize() {
      this.height = document.getElementById("outer").clientHeight;
    }
  },
  mounted() {
    window.addEventListener("resize", this.onResize);
    this.$nextTick(this.onResize);
  }
Run Code Online (Sandbox Code Playgroud)

现场演示

但是是否可以使用纯 CSS 或至少不height显式设置来实现相同的效果?

Sum*_*tel 5

尝试使用 height clac

.v-data-table__wrapper{height:calc(100vh - 150px) !important;}
Run Code Online (Sandbox Code Playgroud)