繁体   English   中英

我该如何解决 [Vue 警告]:数据()中的错误:Laravel Vue 中的“ReferenceError:total is not defined”

[英]How can i solve [Vue warn]: Error in data(): “ReferenceError: total is not defined” in Laravel Vue

我认为我的问题在于数据方法中的利润详细信息的定义。 我已经定义如下,

data(){
   return{
       profitDetails:[],  
         }
      }

我创建的 axio 如下

getProfit(){
     axios.get('api/get-profit').then(response => {
     this.profitDetails = response.data;
     console.log('*************',response.data);
     });
 }

使用 console.log('*************',response.data) 打印以下内容,

控制台日志

使用上面的 axio 我按如下方式访问数据并已经打印了该值,但它提供了控制台错误,就像我在下面附加的图像一样,

{{profitDetails[0].total}} 
{{profitDetails[1].total}} 
{{profitDetails[2].total}} 
{{profitDetails[3].total}} 

但在控制台中显示以下错误控制台日志中的错误

在渲染模板之前,您应该检查是否已从 API 填充了 profitDetails。 例如:

<div v-if="profitDetails.length > 0">

{{profitDetails[0].total}} 
{{profitDetails[1].total}} 
{{profitDetails[2].total}} 
{{profitDetails[3].total}} 

</div>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM