element table 内容是如何实现自适应的?
表格列根据内容自动适应宽度
- fit 参数:无效果
- min-width 参数:无效果
- 重写 table 组件:改动太大,后面考虑
- 动态计算字符串宽度,改变 min-width:效果不太好,过宽,计算公式如下
getStrWidth (str) {
const char = str.match(/[\u2E80-\u9FFF]/g) // 中文
const charLen = char ? char.length : 0
const num = str.match(/\d|\./g) // 数字
const numLen = num ? num.length : 0
const otherLen = str.length - charLen - numLen // 其它
return Math.ceil(charLen * 1.1 + numLen * 0.65 + otherLen * 0.5) * 18
},
请问大佬们,有没有更好的解决方法呢?
:bug: 我的小破站