表格存在且有内容,行数可被打印出来,但是获取到的行数和高度却为0。
代码:
methofor是什么意思ds: { aaa () { console.log('——————————————————测试—————————美味冰淇淋—————————'); console.log('表格html:', this.$refs.abc); console.log('表格.rows:', this.$refs.abc.rows); console.log('表格.rows.length:', this.$refs.abc.rows.length); console.log('表格.offtheight:', this.$refs.abc.offtheight); console.log('——————————————————测试——————————————————'); }}
执行结果:
为何如此?
因为是渲染之前打印的这个数组,看到的却是渲染后的数据,通俗的讲,就是这个dom结构还没加载完,js就执行了。
如何解决?
等dom结构加载完成后再去获取这个数组。
vue等待渲染完执行的函数: vm.$nexttick(function({console.log(…)}))
修改后代码:
methods: { aaa () { this.$nexttick(() => { console.log('——————————————————测试——————————————————'); console.log('表格html:', this.$refs.abc); console.log('表格.rows:', this.$refs.abc.rows); 生产力要素 console前仆后继的意思.log('表格.rows.length:', this.$refs.abc.rows.length); console.log('表格.offtheight:', this.$refs.abc.offtheight); console.log('——————————————————测试——————————————————旅游业发展前景'); }) }}
修改后执行结果:
本文发布于:2023-04-03 12:42:15,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/e0efe20ef88e93019ecdec0fe7256d1b.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:获取表格行数和高度为0的原因及解决方法.doc
本文 PDF 下载地址:获取表格行数和高度为0的原因及解决方法.pdf
留言与评论(共有 0 条评论) |