You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+26-5Lines changed: 26 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -232,9 +232,9 @@ List of 300 VueJS Interview Questions
232
232
|223|[Can I use computed property in another computed property?](#can-i-use-computed-property-in-another-computed-property)|
233
233
|224|[How can I use imported constant in template section?](#How-can-i-use-imported-constant-in-template-section)|
234
234
|225|[Is recommended to use async for computed properties?](#is-recommended-to-use-async-for-computed-properties)|
235
-
|226|[](#)|
236
-
|227|[](#)|
237
-
|228|[](#)|
235
+
|226|[What happens if you use duplicate field names?](#what-happens-if-you-use-duplicate-field-names)|
236
+
|227|[Why the component data must be a function?](#why-the-component-data-must-be-a-function)|
237
+
|228|[What is the reason for recommendation for multi-word component names?](#what-is-the-reason-for-recommendation-for-multi-word-component-names)|
238
238
|229|[](#)|
239
239
|230|[](#)|
240
240
@@ -4723,11 +4723,32 @@ List of 300 VueJS Interview Questions
4723
4723
4724
4724
**[⬆ Back to Top](#table-of-contents)**
4725
4725
4726
-
227. ### ?
4726
+
227. ### Why the component data must be a function?
4727
+
The component data must be a function instead directly providing the object. This is because each instance needs to maintain an independent copy of the returned data object. Otherwise one component instance data changes will impact the data of all other instances.
4728
+
For example, the below code snippets gives an idea on correct approach,
4729
+
```js
4730
+
data: { // Bad
4731
+
message:'Hello'
4732
+
}
4733
+
data:function () { //Good
4734
+
return {
4735
+
message:'Hello'
4736
+
}
4737
+
}
4738
+
```
4727
4739
4728
4740
**[⬆ Back to Top](#table-of-contents)**
4729
4741
4730
-
228. ### ?
4742
+
228. ### What is the reason for recommendation for multi-word component names?
4743
+
Component names should always be multi-word, except for root level or built-in vue components(such as <transition> or <component> etc). This recommendation is to prevents conflicts with existing and future HTML elements, since all HTML elements are a single word.
0 commit comments