I am having a problem with VueJS and Observer objects. I am assigning part of my object to a temporary variable to use later. Then resassign the original part of my object with new data and after 8 seconds revert it back to its original state that I stored in my temporary variable.
I have this Object linked to a list view which renders these 2 different states differently.
I want to stop the observer from observing my temporary variable but I cant work out how.
Below is the code I currently have:
var temporary = core_data.map_data[data.selected]; //This is the variable I dont want to be observed.
core_data.map_data[data.selected].colour = data.colour;
core_data.map_data[data.selected].message = data.message;
core_data.map_data[data.selected].type = "ping";
setTimeout(
function () {
core_data.map_data[data.selected] =temporary;
// console.log(core_data.map_data);
}, 8000);
If you don't want reactivity in vuejs data(){}
object, you can sort of 'clone' and make a copy of the object using JSON's parse/stringify
methods. ex:
var copy = JSON.parse( JSON.stringify( this.original ) );
You can now modify copy
and it won't update your original data property.
After you are done modifying it, you can still update the this.original
as easy as assigning it the value of your copy object.