Skip to content

Commit 2391455

Browse files
committed
Add components interview questions
1 parent 0905f24 commit 2391455

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ List of 300 VueJS Interview Questions
3232
|23 | [What are the supported Mouse Button Modifiers?](#what-are-the-supported-mouse-button-modifiers)|
3333
|24 | [How do you implement two way binding?](#how-do-you-implement-two-way-binding)|
3434
|25 | [What are the supported modifiers on model?](#what-are-the-supported-modifiers-on-model)|
35+
|26 | [What are components and give an example?](#what-are-components-and-give-an-example)|
3536

3637
1. ### What is VueJS?
3738
Vue.js is an open-source, progressive Javascript framework for building user interfaces that aim to be incrementally adoptable. The core library of VueJS is focused on the view layer only, and is easy to pick up and integrate with other libraries or existing projects.
@@ -429,4 +430,25 @@ List of 300 VueJS Interview Questions
429430
```javascript
430431
<input v-model.trim="msg">
431432
```
433+
26. ### What are components and give an example?
434+
Components are reusable Vue instances with a name. They accept the same options as new Vue, such as data, computed, watch, methods, and lifecycle hooks(except few root-specific options like el). Lets take an example of counter component,
435+
```javascript
436+
// Define a new component called button-counter
437+
Vue.component('button-counter', {
438+
template: '<button v-on:click="count++">You clicked me {{ count }} times.</button>'
439+
data: function () {
440+
return {
441+
count: 0
442+
}
443+
},
444+
})
445+
```
446+
Let's use this component inside a root Vue instance created with new Vue
447+
```javascript
448+
<div id="app">
449+
<button-counter></button-counter>
450+
</div>
451+
452+
var vm = new Vue({ el: '#app' });
453+
```
432454

0 commit comments

Comments
 (0)