在vue模板中获取“无法读取未定义的属性'key'”

时间:2019-12-03 11:48:38

标签: vue.js vuejs2 vue-component vuetify.js

所以在我的Vue中,我有一个方法来获取一些数据,创建数组,并将它们传递到另一个Vue文件中,以便在模板中呈现。

方法

 $this->db->select('coalesce(w.name, t.name) as tournament_name, w.tournament_id,<all other tournament_week fields>');

然后我将 this.shoesData.titles = ['Date', 'Model', 'Price Qty', 'Order Qty', 'Discount Qty']; this.shoesData.values = [ new Date(this.getShoes.insertDate).toISOString().slice(0, 10).toString(), this.getShoes.model, parseFloat(this.getShoes.price).toFixed(0).toString()+' tn', parseFloat(this.getShoes.order).toFixed(0).toString()+' tn', parseFloat(this.getShoes.discount).toFixed(0).toString()+' tn' ]; 传递到另一个文件以在其模板中使用

shoesData

<CardMultiValue v-if="shoesData.values" :cardData="shoesData" /> 中,

CardMultiValue

这并不复杂,但是,如果<template> <v-card style="width:100%;height:100%;" :flat="flat" > <v-card-title class="title" v-if="cardData.Title" style="width:100%;height:30px;justify-content:center;align-items:center;padding:5px;">{{cardData.Title}}</v-card-title> <v-card-actions v-if="cardData.Title" style='width:100%;height:calc(100% - 30px);padding:5px;' > <v-container style="padding:0px;height:100%;"> <v-row style="height:100%;"> <v-col :cols="8"> <div v-for="title in cardData.titles" :key="title" :style="'display:flex;align-items:center;font-size:18px;font-weight:bold;height:'+rowHeight+'%;'"> {{title}} </div> </v-col> <v-col :cols="4"> <div v-for="value in cardData.values" :key="value" :style="'display:flex;align-items:center;font-size:18px;height:'+rowHeight+'%;'"> {{value}} </div> </v-col> </v-row> </v-container> </v-card-actions> <v-card-actions v-else style='width:100%;height:100%;padding:5px;' > <v-container style="padding:0px;height:100%;"> <v-row style="height:100%;"> <v-col :cols="8"> <div v-for="a in cardData.titles" :key="a" :style="'display:flex;align-items:center;font-size:18px;font-weight:bold;height:'+rowHeight+'%;'"> {{a}} </div> </v-col> <v-col :cols="4"> <div v-for="b in cardData.values" :key="b" :style="'display:flex;align-items:center;font-size:18px;height:'+rowHeight+'%;'"> {{b}} </div> </v-col> </v-row> </v-container> </v-card-actions> </v-card> this.getShoes.order都恰好是0,我得到

this.getShoes.discount

这必须是模板错误,因为如果我完全删除TypeError: Cannot read property 'key' of undefined at sameVnode (vue.runtime.esm.js?2b0e:5811) at updateChildren (vue.runtime.esm.js?2b0e:6213) at patchVnode (vue.runtime.esm.js?2b0e:6313) at updateChildren (vue.runtime.esm.js?2b0e:6187) at patchVnode (vue.runtime.esm.js?2b0e:6313) at updateChildren (vue.runtime.esm.js?2b0e:6187) at patchVnode (vue.runtime.esm.js?2b0e:6313) at updateChildren (vue.runtime.esm.js?2b0e:6187) at patchVnode (vue.runtime.esm.js?2b0e:6313) at updateChildren (vue.runtime.esm.js?2b0e:6187) this.getShoes.order,我不会收到任何错误。另外,如果我不将数据传递到this.getShoes.discount,也不会出错。

我该如何解决?谢谢

1 个答案:

答案 0 :(得分:2)

this.getshoes 听起来像方法名称。因此,也许将其更改为this.getShoes()。price或将适当的参数(如果有)传递给它; this.getShoes(someParameter).price