0

Under certain conditions I want to reinitialize a component's data to what it started with. As a start, instead of having the properties specified within the data(), I call a function which returns a data object, thus:

data() {
 return this.initialData();
},

How can I call this again in, say, $watch? Can I actually directly write to the data object?

John Moore
  • 6,739
  • 14
  • 51
  • 67

1 Answers1

1

From the API documentation on data:

After the instance is created, the original data object can be accessed as vm.$data.

So it should be as simple as Object.assign(this.$data, this.initialData());

tony19
  • 125,647
  • 18
  • 229
  • 307
Botje
  • 26,269
  • 3
  • 31
  • 41