当前位置:   article > 正文

vue You may have an infinite update loop in a component render function 报错的原因

you may have an infinite update loop in a component render function. found i

今天做东西遇到很多问题,现在都快回忆不起来了,印象特别深刻的就是:

vue You may have an infinite update loop in a component render function 

通过百度,看文章,才明白:

在v-for当中,如果在循环当中调用了方法,而在方法当中去修改data中属性的值,就会导致这样的问题。

至于为何会如此,这怕是要去研究v-for指令和渲染的机制了

我是在使用table的时候,页面mounted的时候从后台请求数据,赋值给tableData,然后就循环展示,但是我在列表里面添加了这个属性::formatter = "statedirection",这个方法去处理这一列的数据,比如转换成百分比之类的。 所以就报了这个错误。emmmmmmm。

解决方法一:

使用全局的formatter

  1. // 使用 :formatter="$formatter.tableColEmpty"
  2. <el-table-column prop="evidenceName"
  3. :formatter="$formatter.tableColEmpty"
  4. show-overflow-tooltip
  5. label="名称">
  6. </el-table-column>
  7. // 定义 可以在main.js文件中
  8. import Formatter from './formatter.js'
  9. Vue.prototype.$formatter = Formatter
  10. // formatter.js
  11. const Formatter = {
  12. // 处理列表-数据为空时的展示
  13. tableColEmpty (row: object, column: object, cellValue?: string | undefined) {
  14. return packEmpty (cellValue, zhCn = false) {
  15. return cellValue|| (zhCn ? '无' : '--')
  16. }
  17. }
  18. }
  19. export default Formatter

 解决方法二:

使用当前页面的过滤器

  1. // 使用
  2. <el-table-column align="left"
  3. label="名称"
  4. show-overflow-tooltip>
  5. <template slot-scope="scope">
  6. <span>{{ scope.row.name| filterEmpty }}</span>
  7. </template>
  8. </el-table-column>
  9. // 过滤器---格式化空数据展示
  10. filterEmpty (val: string) {
  11. return packEmpty (val) {
  12. return val || '--'
  13. }
  14. },

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/402398
推荐阅读
相关标签
  

闽ICP备14008679号