I am working with a basic database that contains several fields including id, product_name, original_price, and discount. The discount field is specified in percentage format.
To populate all the data at once using Axios and display it on the page using v-for
I have utilized the following code:
<ul v-for="product in products">
<li>@{{product.product_name}}</li>
<li>@{{product.original_price}}</li>
<li>@{{product.discount}}</li>
</ul>
Now, I am looking to show the calculated price after applying the discount. To achieve this, I am considering creating a method in my Vue instance as shown below:
calculateDiscount: function(orig_price, discount){
this.discount_amt = discount/100*orig_price;
return this.after_discount = orig_price - this.discount_amt;
}
If I implement this method, how can I invoke it during rendering? Any assistance would be greatly appreciated.