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
+34-24Lines changed: 34 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -457,15 +457,17 @@ List of 300 VueJS Interview Questions
457
457
5. splice()
458
458
6. sort()
459
459
7. reverse()
460
+
460
461
If you perform any of the above mutation method on the list then it triggers view update. For example, push method on array named 'items' trigger a view update,
461
462
```javascript
462
463
vm.todos.push({ message: 'Baz' })
463
464
```
464
-
13. ### What are the array detection nonmutation methods?
465
+
13. ### What are the array detection non-mutation methods?
465
466
The methods which do not mutate the original array but always return a new array are called non-mutation methods. Below are the list of non-mutation methods,
466
467
1. filter()
467
468
2. concat()
468
469
3. slice()
470
+
469
471
For example, lets take a todo list where it replaces the old array with new one based on status filter,
470
472
```javascript
471
473
vm.todos = vm.todos.filter(function (todo) {
@@ -478,13 +480,14 @@ List of 300 VueJS Interview Questions
478
480
479
481
1. When you directly set an item with the index,For example,
480
482
```javascript
481
-
vm.tods[indexOfTodo] = newTodo
483
+
vm.todos[indexOfTodo] = newTodo
482
484
```
483
485
2. When you modify the length of the array, For example,
484
486
```javascript
485
487
vm.todos.length = todosLength
486
488
```
487
489
You can overcome both the caveats using `set` and `splice` methods, Let's see the solutions with an examples,
490
+
488
491
**First use case solution**
489
492
```javascript
490
493
// Vue.set
@@ -520,16 +523,16 @@ List of 300 VueJS Interview Questions
520
523
email: john@email.com
521
524
})
522
525
```
523
-
16. ### How do you use for directive with a range?
524
-
You can also use integer type(say 'n') for v-for directive which repeat the element many times.
526
+
16. ### How do you use v-for directive with a range?
527
+
You can also use integer type(say 'n') for v-for directive which repeats the element many times.
525
528
```javascript
526
529
<div>
527
530
<span v-for="n in 20">{{ n }} </span>
528
531
</div>
529
532
```
530
533
It displays the number 1 to 20.
531
-
17. ### How do you use for directive on template?
532
-
Just similar to v-if directive on template, you can also use a <template> tag with v-for directive to render a block of multiple elements. Let's take a todo example,
534
+
17. ### How do you use v-for directive on template?
535
+
Just similar to v-if directive on template, you can also use a `<template>` tag with v-for directive to render a block of multiple elements. Let's take a todo example,
533
536
```javascript
534
537
<ul>
535
538
<template v-for="todo in todos">
@@ -545,7 +548,6 @@ List of 300 VueJS Interview Questions
545
548
Submit
546
549
</button>
547
550
548
-
\\\\
549
551
methods: {
550
552
show: function (message, event) {
551
553
// now we have access to the native event
@@ -562,23 +564,24 @@ List of 300 VueJS Interview Questions
562
564
4. .self
563
565
5. .once
564
566
6. .passive
567
+
565
568
Let's take an example of stop modifier,
566
-
```javascript
569
+
```html
567
570
<!-- the click event's propagation will be stopped -->
568
571
<a v-on:click.stop="methodCall"></a>
569
572
```
570
573
You can also chain modifiers as below,
571
-
```javascript
574
+
```html
572
575
<!-- modifiers can be chained -->
573
576
<a v-on:click.stop.prevent="doThat"></a>
574
577
```
575
578
20. ### What are key modifiers?
576
-
Vue supports key modifiers on `v-on` for handling keyboard events. Let's take an example of keyup event with enter keycode
577
-
```javascript
579
+
Vue supports key modifiers on `v-on` for handling keyboard events. Let's take an example of keyup event with enter keycode.
580
+
```html
578
581
<!-- only call `vm.show()` when the `keyCode` is 13-->
579
582
<input v-on:keyup.13="show">
580
583
```
581
-
Remembering all the keycodes is really difficult. It supports the full list ofkeycode aliases
584
+
Remembering all the key codes is really difficult. It supports the full list ofkey codes aliases
582
585
1. .enter
583
586
2. .tab
584
587
3. .delete (captures both “Delete” and “Backspace” keys)
@@ -592,14 +595,15 @@ List of 300 VueJS Interview Questions
592
595
Now the above keyup code snippet can be written with aliases as follows,
593
596
```javascript
594
597
<input v-on:keyup.enter="submit">
595
-
(OR)
598
+
// (OR)
596
599
<!-- with shorthand notation-->
597
600
<input @keyup.enter="submit">
598
601
```
602
+
**The use of keyCode events is deprecated and may not be supported innewbrowsers.**
599
603
21. ### How do you define custom key modifier aliases?
600
604
You can define custom key modifier aliases via the global`config.keyCodes`. There are few guidelines for the properties
601
-
1. You can't use cameCase, instead you can use kebab-case with double quotation marks
602
-
2. You can define multiple values in ann array format
605
+
1. You can't use camelCase. Instead you can use kebab-case with double quotation marks
606
+
2. You can define multiple values in an array format
603
607
```javascript
604
608
Vue.config.keyCodes = {
605
609
f1: 112,
@@ -613,6 +617,7 @@ List of 300 VueJS Interview Questions
613
617
2. .alt
614
618
3. .shift
615
619
4. .meta
620
+
616
621
Lets take an example of control modifier with click event,
617
622
```javascript
618
623
<!-- Ctrl + Click -->
@@ -623,20 +628,25 @@ List of 300 VueJS Interview Questions
623
628
1. .left
624
629
2. .right
625
630
3. .middle
631
+
626
632
For example, the usage of `.right` modifier as below
You can use the `v-model` directive to create two-way data bindings on form input, textarea, and select elements. Lets take an example of it using input component,
Remember, v-model will ignore the initial value, checked or selected attributes found on any form elements. So it always use the Vue instance data as the source of truth.
646
+
Remember, v-model will ignore the initial `value`, `checked` or `selected` attributes found on any form elements. So it always use the Vue instance data as the source of truth.
638
647
25. ### What are the supported modifiers on model?
639
648
There are three modifiers supported for v-model directive.
649
+
640
650
**1. lazy:** By default, v-model syncs the input with the data after each input event. You can add the lazy modifier to instead sync after change events.
641
651
```javascript
642
652
<!-- synced after "change" instead of "input" -->
@@ -679,19 +689,19 @@ List of 300 VueJS Interview Questions
679
689
template: '<h2>{{ title }}</h2>'
680
690
})
681
691
```
682
-
Once the props registered, you can pass them as custom atrtributes,
692
+
Once the props are registered, you can pass them as custom atrtributes.
28. ### When component needs a single root element?
687
-
Every component must have a single root element when template has more than one element. Inthis case, you need to wrap a parent element.
697
+
Every component must have a single root element **when template has more than one element**. Inthis case, you need to wrap the elements with a parent element.
688
698
```javascript
689
699
<div class="todo-item">
690
700
<h2>{{ title }}</h2>
691
701
<div v-html="content"></div>
692
702
</div>
693
703
```
694
-
Otherwise there will an error throwing, saying that "wrap those elements with a parent element".
704
+
Otherwise there will an error throwing, saying that "Component template should contain exactly one root element...".
695
705
29. ### How do you communicate from child to parent using events?
696
706
If you want child wants to communicate back up to the parent, then emit an event from child using `$event` object to parent,
697
707
```javascript
@@ -723,7 +733,7 @@ List of 300 VueJS Interview Questions
723
733
The custom events can also be used to create custom inputs that work with v-model. The<input> inside the component must follow below rules,
724
734
1. Bind the value attribute to a value prop
725
735
2. On input, emit its own custom input eventwith the newvalue.
726
-
Lets take a custom-input component as an example,
736
+
Let's take a custom-input component as an example,
0 commit comments