I have a list of items, contained within a javascript array. Similar to the examples found on the vue.js documentation.
This is the workflow I'm struggling with:
- A user clicks "Add".
- I immediately add an item to the list (in the spot where they asked it to be)
- I send an ajax request to the server to create the item.
- The call returns with the database row for the new item.
I'm using the database primary key as my vue key - which I have no way of knowing up to the point the ajax call finally gets back to me. But if I simply update the ID on the object, I end up with that row transitioning out and then back in.
Is there a way to tell vue that I'm changing the ID of an item?
My ideal case would be something along the lines of:
click: function () {
let item = {
id: "placeholder id, possibly randomly generated"
}
this.array.splice(index, 0, item);
ajax_call().complete(function (new_id) {
// item = data.new_id
vue.update_id_for_object(item, data.new_id)
})
}
The commented out line is the one that causes the undesired transition.
Someone voted to close this as a duplicate of this question - as far as I can tell, it's talking about how to set ids dynamically which I'm already doing in my example. Feel free to clarify how it helps my issue though.