1

I have a fairly complex app which take the user through a 5-step process. I have a data object called userData which contains all their entry info (name, age, weight, heigh,etc).

At a certain point in the app I would like to take a snapshot of this data, and recall it if I need to. If I write it to a new var in the data object, it is dynamic. I want to create a static copy or snapshot of the data at stage 5.

How can I achieve this?

I have looked at

http://rc.vuejs.org/guide/application.html#State_Management

but maybe does not seem the way to go.

LeBlaireau
  • 17,133
  • 33
  • 112
  • 192
  • You might want to look at using something like http://vuejs.github.io/vuex/ . Failing that you could just declare an object outside of the component's scope. One issue you might bump into is has been addressed here: http://stackoverflow.com/questions/30578254/does-vue-js-have-a-built-in-way-to-add-a-copy-of-a-persistent-object-to-a-repeat – Rwd Apr 27 '16 at 11:56
  • thanks Ross, heard a bit about Vuex looks interesting. – LeBlaireau Apr 27 '16 at 12:13

1 Answers1

1

If you mean you just need to store a static copy of the data at that point in time, you can simply use any javascript method: Object.assign() and store the variable in your data prop or if it doesn't need to be bound to the template, in your $options

this.$options.userCache = Object.assign({}, this.userData)

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign

Tremendus Apps
  • 1,497
  • 12
  • 20