我希望从 Vue.js 2 中的计算属性中推送到数组,Vue 正在 Laravel 中使用,我得到以下响应。
createSelection:“(评估期间出错)”
正在使用以下代码:
<template>
<div>
<div>Credits carried through: {{ credits }}</div>
<div v-for="meal in meals">
{{meal}}
<input :id="meal" :name="meal" v-model.number="creditsPerMeal[meal]" type="number">
</div>
<div>
Credits used: {{creditsSum}}/{{credits}}
</div>
</div>
</template>
<script>
export default {
mounted() {
console.log('Component ready.');
console.log(JSON.parse(this.f));
},
props: ['f','c'],
name: 'credits',
data: function () {
var meals = JSON.parse(this.f)
var creditsPerMeal = {}
for (var i = 0; i < meals.length; i++) {
creditsPerMeal[meals[i]] = 0
}
var createSelection = []
return {
credits: this.c,
meals,
creditsPerMeal
}
},
computed: {
creditsSum () {
return Object.values(this.creditsPerMeal).reduce((a, b) => a + b, 0)
},
createSelection: function (){
for (var i = 0; i < meals.length; i++) {
createSelection.push({
food: meals[i],
quantity: creditsPerMeal[meals[i]]
})
}
}
}
}
</script>