|
| 1 | +:::anchor Dynamic Table Width(calc css function) |
| 2 | + |
| 3 | +:::demo 1、You can use [calc css function](<https://developer.mozilla.org/en-US/docs/Web/CSS/calc()>) to achieve table dynamic width<br>2、Try changing the browser width to see the effect |
| 4 | + |
| 5 | +```html |
| 6 | +<template> |
| 7 | + <ve-table style="width:calc(55vw - 10px);" :columns="columns" :table-data="tableData" /> |
| 8 | +</template> |
| 9 | + |
| 10 | +<script> |
| 11 | + export default { |
| 12 | + data() { |
| 13 | + return { |
| 14 | + columns: [ |
| 15 | + { field: "name", key: "a", title: "Name", width: 100 }, |
| 16 | + { field: "date", key: "b", title: "Tel", width: 200 }, |
| 17 | + { field: "hobby", key: "c", title: "Hobby", width: 300 }, |
| 18 | + { field: "address", key: "d", title: "Address", width: 300 }, |
| 19 | + ], |
| 20 | + tableData: [ |
| 21 | + { |
| 22 | + name: "John", |
| 23 | + date: "1900-05-20", |
| 24 | + hobby: "coding and coding repeat", |
| 25 | + address: "No.1 Century Avenue, Shanghai", |
| 26 | + }, |
| 27 | + { |
| 28 | + name: "Dickerson", |
| 29 | + date: "1910-06-20", |
| 30 | + hobby: "coding and coding repeat", |
| 31 | + address: "No.1 Century Avenue, Beijing", |
| 32 | + }, |
| 33 | + { |
| 34 | + name: "Larsen", |
| 35 | + date: "2000-07-20", |
| 36 | + hobby: "coding and coding repeat", |
| 37 | + address: "No.1 Century Avenue, Chongqing", |
| 38 | + }, |
| 39 | + { |
| 40 | + name: "Geneva", |
| 41 | + date: "2010-08-20", |
| 42 | + hobby: "coding and coding repeat", |
| 43 | + address: "No.1 Century Avenue, Xiamen", |
| 44 | + }, |
| 45 | + { |
| 46 | + name: "Jami", |
| 47 | + date: "2020-09-20", |
| 48 | + hobby: "coding and coding repeat", |
| 49 | + address: "No.1 Century Avenue, Shenzhen", |
| 50 | + }, |
| 51 | + ], |
| 52 | + }; |
| 53 | + }, |
| 54 | + }; |
| 55 | +</script> |
| 56 | +``` |
| 57 | + |
| 58 | +::: |
0 commit comments