javascript - 在Vue中使用props时数组元素属性未定义
问题描述
我正在尝试在 Vue 中使用 Prop 将数组传递给子组件。不知何故,我能够访问所有变量及其属性,除了其中一个,maxAmt。我听说这可能是由于我们使用 camelCase 与 camel-case 的方式,但是在更改变量属性名称后,没有任何效果。这是我的代码:
编辑:只是为了澄清,我能够访问并显示maxAmt
在父组件中,但不能在子组件中。
父组件:
<script>
import database from '../firebase.js'
export default {
data(){
return{
grantsList:[]
}
},
methods:{
fetchItems:function(){
database.collection('Grants').get().then((querySnapShot)=>{
querySnapShot.forEach(doc=>{
let grant={}
doc=doc.data()
grant.name=doc.Name
grant.grantInfo = doc.GrantInfo
grant.maxamt = doc.maxAmt // PROBLEM VARIABLE
grant.grantAmount = doc.GrantAmount
grant.detail = doc.Detail
grant.apply = doc.Apply
console.log(grant)
//console.log(grant.maxAmt)
grant.show=false
this.grantsList.push(grant)
})
})
},
open:function(link){
window.open(link)
}
},
created(){
this.fetchItems()
}
}
</script>
子组件:
<script>
export default {
props:{
grantsList:{
Type:Array
}
},
data(){
return {
x: 0
}
},
methods: {
getTotal(){
var sum = 'hi'
this.grantsList.forEach(g => {
//console.log(g.amount) // correct output
console.log(g.maxamt) // THIS PART IS UNDEFINED
sum += g.amount
});
console.log(sum)
this.x = sum
}
},
}
</script>
使用console.log(g.maxamt),我明白undefined
了,但是其他变量以某种方式显示,所以我真的很困惑只有一个属性是如何无法显示的。
解决方案
推荐阅读
- haskell - 为什么这个的第二个版本在指数时间内运行?
- android - 导航组件可以在活动之间使用吗?
- typescript - Typescript 解构对象和对象的内部属性
- sql - Power BI 中没有周六和周日的上一个日期
- r - 如何在使用 pivot_wider() 后保留原始变量,而无需手动创建临时变量来传播数据?
- java - 如何验证从 yaml 文件开始的输入字段
- amazon-web-services - 应该用作 Runner Manager 并生成新机器的 EC2 实例正在运行管道作业
- node.js - 无法连接到 node.js API、EC2 AWS [已解决]
- python - 新类中的 torch.load(ml_model) 我收到 AttributeError: Can't get attribute 'ResNet1D' on
- node.js - 有没有办法为 package.json 中的相同依赖项指定不同的路径?