多层嵌套时,直接用%会根据父级容器来计算,因此静态时用vw或px,
使用vw时,需要容器宽度也用vw或者百分比,容器需要固定宽度时效果不佳
动态时用容器宽度减去其他单元格宽度
示例
/**
* contentWidth: 容器宽度
**/
const createHtmlNode = (text, className) => {
let topval = `calc(${contentWidth} - ${num}rem)`;
return h(
'div',
{
class: [className || 'node'],
style: {
width: topval
},
attrs: {
'v-html':text
},
},
text
)
}