Ich möchte eine Funktion als Dateneigenschaft verwenden. Dies scheint gut zu funktionieren, wie im Fall der Dateneigenschaft "Arbeiten". Allerdings benötige ich diesen Kontext in der Funktion, damit ich Werte berechnen kann, die in der this.shoppingCart (einer anderen Eigenschaft) gespeichert sind.Bind vuejs Funktion als Daten mit Kontext vuejs
Ist das möglich? Wenn ja, was mache ich falsch?
new Vue({
el: '#vueApp',
data: {
shoppingCart: [],
works : function() {
return "testfunc";
},
totalPriceCalcProperty : function() {
this.totalPrice = this.shoppingCart.reduce(function(total, cartItem){
console.log(total, cartItem);
return total + parseFloat(cartItem.price);
}, 0);
}
},
methods: {
totalPriceCalc: function() {
this.totalPrice = this.shoppingCart.reduce(function(total, cartItem){
console.log(total, cartItem);
return total + parseFloat(cartItem.price);
}, 0);
},
}