TypeError: Cannot read property '0' of undefined

左手的ㄟ右手 2022-04-10 01:40 402阅读 0赞

1、错误描述

  1. [Vue warn]: Error in render: "TypeError: Cannot read property '0' of undefined vue.runtime.esm.js:587
  2. "
  3. found in
  4. --->
  5. <ElTableFooter>
  6. <ElTable>
  7. <CurrentStock> at src\views\table\controlCenter\CurrentStock.vue
  8. <ElRow>
  9. <ControlCenter> at src\views\table\controlCenter\index.vue
  10. <AppMain> at src\views\layout\components\AppMain.vue
  11. <Layout> at src\views\layout\Layout.vue
  12. <App> at src\App.vue
  13. <Root>
  14. TypeError: Cannot read property '0' of undefined vue.runtime.esm.js:1737
  15. at element-ui.common.js:13072
  16. at Proxy.renderList (vue.runtime.esm.js:3701)
  17. at Proxy.render (element-ui.common.js:13060)
  18. at VueComponent.Vue._render (vue.runtime.esm.js:4540)
  19. at VueComponent.updateComponent (vue.runtime.esm.js:2784)
  20. at Watcher.get (vue.runtime.esm.js:3138)
  21. at Watcher.run (vue.runtime.esm.js:3215)
  22. at flushSchedulerQueue (vue.runtime.esm.js:2977)
  23. at Array.<anonymous> (vue.runtime.esm.js:1833)
  24. at flushCallbacks (vue.runtime.esm.js:1754)

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3lvdTIzaGFpNDU_size_16_color_FFFFFF_t_70 TypeError: Cannot read property ‘0’ of undefined

2、错误原因

  1. <template>
  2. <el-table :data="tabList" style="height:400px;overflow-y:auto;" show-summary sum-text="合计" :summary-method="formatSummary">
  3. <el-table-column label="名称" prop="name" align="center"></el-table-column>
  4. <el-table-column v-for="(m,index) in tabHeadList" :key="index" align="center" :label=m :formatter="formatZ" :prop="m"></el-table-column>
  5. <!-- <el-table-column label="合计">
  6. <template slot-scope="scope">
  7. {
  8. {scope.row}}
  9. </template>
  10. </el-table-column> -->
  11. </el-table>
  12. </template>
  13. formatSummary(param) {
  14. console.log(param)
  15. }
  16. formatSummary函数需要一个返回值,如果没有的话,会出现报错

3、解决办法

  1. formatSummary(param) {
  2. const { columns, data } = param;
  3. const sums = [];
  4. columns.forEach((column, index) => {
  5. if (index === 0) {
  6. sums[index] = '合计';
  7. return;
  8. }
  9. const values = data.map(item => Number(item[column.property]));
  10. if (!values.every(value => isNaN(value))) {
  11. sums[index] = values.reduce((prev, curr) => {
  12. const value = Number(curr);
  13. if (!isNaN(value)) {
  14. return prev + curr;
  15. } else {
  16. return prev;
  17. }
  18. }, 0);
  19. sums[index] = Math.round(sums[index]);
  20. }
  21. });
  22. return sums;
  23. }

发表评论

表情:
评论列表 (有 0 条评论,402人围观)

还没有评论,来说两句吧...

相关阅读