Vue.js invoice transaction, project push input
P粉561749334
P粉561749334 2023-08-30 23:57:40
0
1
435

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


P粉561749334
P粉561749334

reply all (1)
P粉421119778

To show only the input box when the button is pressed, you should usev-ifand check if the key exists in the project. I'll provide an example fordescriptionbut you can apply it to all input boxes you want.

So when you add a new item, do not adddescriptionlike this:

methods: { addInvoice() { this.invoiceItems.push({ name: "", quantity: 0, unit_price: 0, vat_rate: 18, net_total: 0, }); }, },

And check ifitem.descriptionexists ininputofdescription:

... ...
The

addDescmethod will add the key to the project and set it to empty:

addDesc(index){ Vue.set(this.invoiceItems[index], "description", ""); }

deleteDescmethod will completely delete the key from the project:

deleteDesc(index){ Vue.delete(this.invoiceItems[index], "description"); }

Now, when you click theadd descriptionbutton, thedescriptioninput box will appear, and when you click thedelete descriptionbutton, thedescriptionThe input box will disappear.

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!