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
---> 

  
         
    at src\views\table\controlCenter\CurrentStock.vue
           
    
             
      at src\views\table\controlCenter\index.vue
               
       at src\views\layout\components\AppMain.vue
                 
         at src\views\layout\Layout.vue
                   
            at src\App.vue
                     
             

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. (vue.runtime.esm.js:1833)
    
at flushCallbacks (vue.runtime.esm.js:1754)
TypeError: Cannot read property '0' of undefined_第1张图片 TypeError: Cannot read property '0' of undefined

2、错误原因

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;
}

 

你可能感兴趣的:(Vue.js)