前提的需求:
公司做了一个设计器,我们对一些组件进行二次封装。移动端我采取了vant这个UI框架。在写textarea的时候,发现<van-field type="textarea">的时候,autosize中的minHeight失效的问题。
解决minHeight失效问题,只需要在需要使用自适应的时候,将传递过来的minHeight转成行数,赋值给rows就行。
我们是后端给我们传的自适应的值是行数,最小行和最大行。所以这里需要将行数改为高度。从element参考的文件:
calcTextareaHeight.js(将行数换算成高度,并且返回了minHeight,height,maxHeight。入参是$el,minRows,maxRows)
let hiddenTextarea
const HIDDEN_STYLE = `
height:0 !important;
visibility:hidden !important;
overflow:hidden !important;
position:absolute !important;
z-index:-1000 !important;
top:0 !important;
right:0 !important
`
const CONTEXT_STYLE = [
'letter-spacing',
'line-height',
'padding-top',
'padding-bottom',
'font-family',
'font-weight',
'font-size',
'text-rende