TypeError: Cannot read property '0' of undefined 左手的ㄟ右手 2022-04-10 01:40 280阅读 0赞 1、错误描述 [Vue warn]: Error in render: "TypeError: Cannot read property '0' of undefined vue.runtime.esm.js:587 " found in ---> <ElTableFooter> <ElTable> <CurrentStock> at src\views\table\controlCenter\CurrentStock.vue <ElRow> <ControlCenter> at src\views\table\controlCenter\index.vue <AppMain> at src\views\layout\components\AppMain.vue <Layout> at src\views\layout\Layout.vue <App> at src\App.vue <Root> TypeError: Cannot read property '0' of undefined vue.runtime.esm.js:1737 at element-ui.common.js:13072 at Proxy.renderList (vue.runtime.esm.js:3701) at Proxy.render (element-ui.common.js:13060) at VueComponent.Vue._render (vue.runtime.esm.js:4540) at VueComponent.updateComponent (vue.runtime.esm.js:2784) at Watcher.get (vue.runtime.esm.js:3138) at Watcher.run (vue.runtime.esm.js:3215) at flushSchedulerQueue (vue.runtime.esm.js:2977) at Array.<anonymous> (vue.runtime.esm.js:1833) 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、错误原因 <template> <el-table :data="tabList" style="height:400px;overflow-y:auto;" show-summary sum-text="合计" :summary-method="formatSummary"> <el-table-column label="名称" prop="name" align="center"></el-table-column> <el-table-column v-for="(m,index) in tabHeadList" :key="index" align="center" :label=m :formatter="formatZ" :prop="m"></el-table-column> <!-- <el-table-column label="合计"> <template slot-scope="scope"> { {scope.row}} </template> </el-table-column> --> </el-table> </template> formatSummary(param) { console.log(param) } formatSummary函数需要一个返回值,如果没有的话,会出现报错 3、解决办法 formatSummary(param) { const { columns, data } = param; const sums = []; columns.forEach((column, index) => { if (index === 0) { sums[index] = '合计'; return; } const values = data.map(item => Number(item[column.property])); if (!values.every(value => isNaN(value))) { sums[index] = values.reduce((prev, curr) => { const value = Number(curr); if (!isNaN(value)) { return prev + curr; } else { return prev; } }, 0); sums[index] = Math.round(sums[index]); } }); return sums; } [watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3lvdTIzaGFpNDU_size_16_color_FFFFFF_t_70]: /images/20220404/7cbab6cb3de24198b558f27370cc406c.png
还没有评论,来说两句吧...