I'm trying to do an invoice transaction using Vue.js. My question is: User may want to write description for 1 product or may want to apply discount (on request). I want the specified input to show up no matter which item he wants to add. (Each line can only have one description, discount)
Therefore, on demand When you press the "Description, Discount and Discount Rate" button, the input for the relevant rows will be pushed.
Thank you very much for your help.
jsfiddle
const app = new Vue({ el: "#app", data: { invoiceItems: [ { name: "", quantity: 0, unit_price: 0, vat_rate: 18, net_total: 0, description: '', discount_value: 0, discount_rate:'usd' }, ], }, methods: { addInvoice() { this.invoiceItems.push({ name: "", quantity: 0, unit_price: 0, vat_rate: 18, net_total: 0, description: '', discount_value: 0, discount_rate:'usd' }); }, removeIncoiceItem(index) { this.invoiceItems.splice(index, 1); }, }, });
Name Unit Price Vat Rate Action
To show only the input box when the button is pressed, you should use
v-if
and check if the key exists in the project. I'll provide an example fordescription
but you can apply it to all input boxes you want.So when you add a new item, do not add
description
like this:And check if
Theitem.description
exists ininput
ofdescription
:addDesc
method will add the key to the project and set it to empty:deleteDesc
method will completely delete the key from the project:Now, when you click the
add description
button, thedescription
input box will appear, and when you click thedelete description
button, thedescription
The input box will disappear.