0👍
I believe that the best would be to calculate the total either with a computed property, so the component won’t recalculate the total too many times, or a Vuex getter could be created using the same logic.
computed: {
total () {
this.$store.state.cartdata.reduce((result, product) => {
// We need to ensure that the property is of the type Number.
result += Number(product.price);
return result;
}, 0);
},
},
Please note that the property product.price
might be wrong, as the data structure wasn’t provided.
- [Vuejs]-Error trying to attach external script to single file component in Vue
- [Vuejs]-Use dynamic import in vue router with laravel mix
Source:stackexchange.com