• TypeError: Cannot read property '0' of undefined


    1、错误描述

     [Vue warn]: Error in render: "TypeError: Cannot read property '0' of undefined         vue.runtime.esm.js:587
    "
    found in
    ---> 
    <ElTableFooter>
      <ElTable>
             
       <CurrentStock> at srcviews	ablecontrolCenterCurrentStock.vue
               
        <ElRow>
                 
         <ControlCenter> at srcviews	ablecontrolCenterindex.vue
                   
          <AppMain> at srcviewslayoutcomponentsAppMain.vue
                     
            <Layout> at srcviewslayoutLayout.vue
                       
               <App> at srcApp.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)
    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;
    }
  • 相关阅读:
    你所不知道的React Hooks
    DataRow的RowState属性变化
    gRPC详解
    Protobuf简明教程
    docker容器内没有权限
    Locust高并发情况下的性能优化与分布式场景的应用
    Docker容器日志打满机器的解决方式
    Django单测详解
    使用Flask+uwsgi+Nginx部署Flask正式环境
    Locust-分布式执行
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13313751.html
Copyright © 2020-2023  润新知