Problem Statement
What is the purpose of the data() function inside a component?
Explanation
data() returns a fresh object that Vue makes reactive for each component instance. Returning a factory function avoids shared state across instances. Properties returned from data() are tracked; updates automatically re-render the template.
Code Solution
SolutionRead Only
export default {
name: 'ExampleComponent',
data(){
return { message: 'Hello', count: 0 }
}
}Practice Sets
This question appears in the following practice sets: