vue报错 Error in callback for immediate watcher "height": "TypeError: Cannot read property 'style' of

vue报错vue.esm.js?eaf6:628 [Vue warn]: Error in callback for immediate watcher "height": "TypeError: Cannot read property 'style' of undefined"

TypeError: Cannot read property 'style' of undefined

如下:

vue报错 Error in callback for immediate watcher

vue报错 Error in callback for immediate watcher

vue报错 Error in callback for immediate watcher

vue报错 Error in callback for immediate watcher

报错原因是tableData为空数组,所以this.monthTradingTableHeight 这时为空

 

解决:

1.判断没有数据时不渲染,添加一个暂无数据的样式

代码:

vue报错 Error in callback for immediate watcher

效果:

vue报错 Error in callback for immediate watcher

 

 

 

 

2.或html代码不变,修改js,没有数据时也给this.monthTradingTableHeight赋个值或给'auto',就不会报错了

代码:

this.monthTradingTableHeight = tableData.length > 9 ? '310' : 'auto'

效果:

vue报错 Error in callback for immediate watcher

这里我选择的是第一种解决方法,整体添加一个暂无数据的样式。

你可能感兴趣的:(项目中遇到问题)