【发布时间】:2020-08-05 23:17:42
【问题描述】:
我正在尝试从我的数据库中传递一个值,然后将该值分配给我的Vue Component 中的一个变量。这成功地从数据库中获取数据,但是在将该值分配给组件中的变量时出现错误:
- “TypeError:无法读取未定义的属性‘数据’”
Vue 组件:
import TransactionsService from '@/services/TransactionsService'
export default {
components: {
},
data(){
return {
transactions: null,
product: null,
amount: null
}
},
async mounted() {
try{
this.transactions = (await TransactionsService.index()).data.transactions
for( transaction in transactions){
this.amount = transaction.amount
}
console.log(amount)
this.userId = this.$store.state.user.priviledge
} catch(error){
this.error = error.response.data.message
}
}
}
我想将transaction.amount 的值赋给变量amount
【问题讨论】:
-
TransactionsService.index()的返回数据结构是什么 -
@AndrewNolan 一个数组。我已将其添加到问题中
-
在通往
transactions的路径中似乎不是data -
这很奇怪,因为我在我的 html 部分使用
transactions,而我使用v-for来访问和显示这些值。所以我不确定为什么我现在在尝试将其分配给变量时为transactions收到此错误 -
我把它改成了
console.log(error),现在说transaction没有定义
标签: node.js vue.js vuejs2 vue-component