Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
233 views
in Technique[技术] by (71.8m points)

vue.js - VUEJS - Append <tr> element when button pressed

Question picture

I have a table in my Vuejs project similar to the one that I shared its screenshot above.

My question is; How can I delete a <tr> element from the table when the Delete button of it is pressed for each row?

On the other hand, I want the Add button at the top right of the table to be functional as well. When I click the Add button, I want another <tr> element to be created at the bottom of the table. However, there should be input fields on this element where the user can enter information for each column. After the user has written the information in each column, that row should be added to the table. How can I do that?

question from:https://stackoverflow.com/questions/65641019/vuejs-append-tr-element-when-button-pressed

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

if I am correct you are using v-for loop to render all <tr>s

then use the v-for with index like v-for="(obj, index) in objects" to obtain index

to add use Array.prototype.push() to add empty row e.g. objects.push({x: null, y: null})

to remove use Array.prototype.splice() e.g objects.splice(index, 1)

just assign those functionalities to respective buttons.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...