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
+43-36Lines changed: 43 additions & 36 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1160,8 +1160,8 @@ List of 300 VueJS Interview Questions
1160
1160
</style>
1161
1161
```
1162
1162
48. ### Is Single File Components violating separation of concerns?
1163
-
As per the latest modern UI development, separation of concerns is not equal to separation of file types. So it is preferred to divide codebase layers into loosely-coupled components and compose them instead of dividing the codebase into three huge layers that interweave with one another. This way it makes Single File Components more cohesive and maintainable by combining template, logic and styles together inside a component.
1164
-
You can also still maintain javascript and CSS files as separate with hot-reloading and pre-compilation features. For example,
1163
+
As for the latest modern UI development, separation of concerns is not equal to separation of file types. So it is preferred to divide codebase layers into loosely-coupled components and compose them instead of dividing the codebase into three huge layers that interweave with one another. This way makes Single File Components more cohesive and maintainable by combining template, logic and styles together inside a component.
1164
+
You can also still maintain javascript and CSS files separately with hot-reloading and pre-compilation features. For example,
1165
1165
```
1166
1166
<template>
1167
1167
<div>This section will be pre-compiled and hot reloaded</div>
@@ -1180,7 +1180,7 @@ List of 300 VueJS Interview Questions
1180
1180
1. mustache interpolations
1181
1181
2. v-bind expressions
1182
1182
1183
-
For example, Let's define local filter named camelcase in a component’s options
1183
+
For example, Let's define a local filter named capitalize in a component’s options
1184
1184
```javascript
1185
1185
filters: {
1186
1186
capitalize:function (value) {
@@ -1193,7 +1193,7 @@ List of 300 VueJS Interview Questions
1193
1193
Now you can use the filter in either mustache interpolation or v-bind expression,
1194
1194
```javascript
1195
1195
<!--in mustaches -->
1196
-
{{ username |camelcase }}
1196
+
{{ username |capitalize }}
1197
1197
1198
1198
<!--in v-bind -->
1199
1199
<div v-bind:id="username | capitalize"></div>
@@ -1227,12 +1227,12 @@ List of 300 VueJS Interview Questions
1227
1227
52. ### How do you chain filters?
1228
1228
You can chain filters one after the other to perform multiple manipulations on the expression. The generic structure of filter chain would be as below,
1229
1229
```javascript
1230
-
{{ message | filterA | filterB | filterB ...}}
1230
+
{{ message | filterA | filterB | filterB ...}}
1231
1231
```
1232
1232
In the above chain stack, you can observe that message expression applied with three filters, each separated by a pipe(|) symbol. The first filter(filterA) takes the expression as a single argument and the result of the expression becomes an argument for second filter(filterB) and the chain continuefor remaining filters.
1233
1233
For example, if you want to transform date expression with a full date format and uppercase then you can apply dateFormat and uppercase filters as below,
1234
-
```javascirpt
1235
-
{{ birthday | dateFormat | uppercase}}
1234
+
```javascript
1235
+
{{ birthday | dateFormat | uppercase}}
1236
1236
```
1237
1237
1238
1238
53. ### Is it possible to pass parameters for filters?
@@ -1247,14 +1247,14 @@ List of 300 VueJS Interview Questions
1247
1247
```
1248
1248
54. ### What are plugins and their various services?
1249
1249
1250
-
Plugins provides global-level functionality to Vue application. The plugins provides various services,
1250
+
Plugins provides global-level functionality to Vue application. The plugins provide various services,
1251
1251
1. Add some global methods or properties. For example, vue-custom-element
1252
1252
2. Add one or more global assets (directives, filters and transitions). For example, vue-touch
1253
1253
3. Add some component options by global mixin. For example, vue-router
1254
1254
4. Add some Vue instance methods by attaching them to Vue.prototype.
1255
1255
5. A library that provides an API of its own, while at the same time injecting some combination of the above. For example, vue-router
1256
1256
55. ### How to create a plugin?
1257
-
The Plugin is created by exposing an install method which takes Vue constructor as a first argument along with options. The structure of VueJS plugin with possible functionality would be as follows,
1257
+
The Plugin is created by exposing an `install` method which takes Vue constructor as a first argument along with options. The structure of VueJS plugin with possible functionality would be as follows,
1258
1258
```javascript
1259
1259
MyPlugin.install=function (Vue, options) {
1260
1260
// 1. add global method or property
@@ -1295,7 +1295,7 @@ List of 300 VueJS Interview Questions
1295
1295
})
1296
1296
```
1297
1297
57. ### What are mixins?
1298
-
Mixin gives us a way to distribute reusable functionality in Vue components. These reusable functions are merged with existing functions. A mixin object can contain any component options. Let us take an example of mixin with created lifecycle which can be shared across components,
1298
+
Mixin gives us a way to distribute reusable functionalities in Vue components. These reusable functions are merged with existing functions. A mixin object can contain any component options. Let us take an example of mixin with `created` lifecycle which can be shared across components,
1299
1299
```javascript
1300
1300
constmyMixin= {
1301
1301
created(){
@@ -1307,7 +1307,7 @@ List of 300 VueJS Interview Questions
1307
1307
mixins: [myMixin]
1308
1308
})
1309
1309
```
1310
-
**Note:**Multiple mixins can be specified in the mixin array of the component.
1310
+
**Note:**Multiple mixins can be specified in the mixin array of the component.
1311
1311
58. ### What are global mixins?
1312
1312
Sometimes there is a need to extend the functionality of Vue or apply an option to all Vue components available in our application. In this case, mixins can be applied globally to affect all components in Vue. These mixins are called as global mixins. Let's take an example of global mixin,
1313
1313
```javascript
@@ -1323,7 +1323,7 @@ List of 300 VueJS Interview Questions
1323
1323
```
1324
1324
In the above global mixin, the mixin options spread across all components with the console running during the instance creation. These are useful during test, and debugging or third party libraries. At the same time, You need to use these global mixins sparsely and carefully, because it affects every single Vue instance created, including third party components.
1325
1325
59. ### How do you use mixins in CLI?
1326
-
Using Vue CLI, mixins can be specified anywhere in the project folder but preferably within `/src/mixins` for ease of access. Once these mixins are created in a `.js` file and exposed with the `export` keyword, they can be imported in any component with the `import` keyword and its file path.
1326
+
Using Vue CLI, mixins can be specified anywhere in the project folder but preferably within `/src/mixins` for ease of access. Once these mixins are created in a `.js` file and exposed with the `export` keyword, they can be imported in any component with the `import` keyword and their file paths.
1327
1327
60. ### What are the merging strategies in mixins?
1328
1328
When a mixin and the component itself contain overlapping options, the options will be merged based on some strategies.
1329
1329
1. The data objects undergo a recursive merge, with the component’s data taking priority over mixins in cases of overlapping or conflicts.
@@ -1433,7 +1433,7 @@ List of 300 VueJS Interview Questions
1433
1433
<input v-focus>
1434
1434
```
1435
1435
63. ### How do you register directives locally?
1436
-
You can also register directives locally(apart from globally) using directives option with in component as below,
1436
+
You can also register directives locally(apart from globally) using directives option in component as below,
1437
1437
```javascript
1438
1438
directives: {
1439
1439
focus: {
@@ -1454,20 +1454,21 @@ List of 300 VueJS Interview Questions
1454
1454
2. inserted: This hook occurs once the element is inserted into the parent DOM.
1455
1455
3. update: This hook is called when the element updates, but children haven't been updated yet.
1456
1456
4. componentUpdated: This hook is called once the component and the children have been updated.
1457
-
5. unbind: This hook is called once the directive is removed.
1458
-
**Note:** There are several arguments can be passed to the above hooks.
1457
+
5. unbind: This hook is called only once when the directive is removed.
1458
+
1459
+
**Note:** There are several arguments that can be passed to the above hooks.
1459
1460
65. ### What are the directive Hook Arguments?
1460
-
All the hooks have **el, binding, and vnode** as arguments. Along with that, **update and componentUpdated** hooks expose oldVnode, to differentiate between the older value passed and the newer value. Below are the arguments passed to the hooks,
1461
-
1. el: The element the directive is bound to and it can be used to directly manipulate the DOM.
1462
-
2. binding: An object containing the following properties.
1463
-
1. name: The name of the directive, without the v- prefix.
1464
-
2. value: The value passed to the directive. For example in v-my-directive="1 + 1", the value would be 2.
1465
-
3. oldValue: The previous value, only available in update and componentUpdated. It is available whether or not the value has changed.
1466
-
4. expression: The expression of the binding as a string. For example in v-my-directive="1 + 1", the expression would be "1 + 1".
1467
-
5. arg: The argument passed to the directive, if any. For example in v-my-directive:foo, the arg would be "foo".
1468
-
6. modifiers: An object containing modifiers, if any. For example in v-my-directive.foo.bar, the modifiers object would be { foo: true, bar: true }.
1469
-
3. vnode: The virtual node produced by Vue’s compiler.
1470
-
4. oldVnode: The previous virtual node, only available in the update and componentUpdated hooks.
1461
+
All the hooks have `el`, `binding`, and `vnode` as arguments. Along with that, **update** and **componentUpdated** hooks expose `oldVnode`, to differentiate between the older value passed and the newer value. Below are the arguments passed to the hooks,
1462
+
1. `el`: The element the directive is bound to and it can be used to directly manipulate the DOM.
1463
+
2. `binding`: An object containing the following properties.
1464
+
1. `name`: The name of the directive, without the `v-` prefix.
1465
+
2. `value`: The value passed to the directive. For example in `v-my-directive="1 + 1"`, the value would be 2.
1466
+
3. `oldValue`: The previous value, only available in update and componentUpdated. It is available whether or not the value has changed.
1467
+
4. `expression`: The expression of the binding as a string. For example in `v-my-directive="1 + 1"`, the expression would be "1 + 1".
1468
+
5. `arg`: The argument passed to the directive, if any. For example in v-my-directive:foo, the arg would be "foo".
1469
+
6. `modifiers`: An object containing modifiers, if any. For example in v-my-directive.foo.bar, the modifiers object would be `{ foo:true, bar:true }`.
1470
+
3. `vnode`: The virtual node produced by Vue’s compiler.
1471
+
4. `oldVnode`: The previous virtual node, only available in the update and componentUpdated hooks.
1471
1472
1472
1473
The arguments can be represented diagrammatically across the hooks as below,
@@ -1487,14 +1488,14 @@ List of 300 VueJS Interview Questions
1487
1488
})
1488
1489
```
1489
1490
67. ### What is function shorthand in directive hooks?
1490
-
In few cases, you may want the same behavior on **bind and update** hooks irrespective of other hooks. In this situation you can use function shorthand,
1491
+
In few cases, you may want the same behavior on `bind` and `update` hooks irrespective of other hooks. In this situation you can use function shorthand,
1491
1492
```javascript
1492
1493
Vue.directive('theme-switcher', function (el, binding) {
1493
1494
el.style.backgroundColor=binding.value
1494
1495
})
1495
1496
```
1496
1497
68. ### What is the benefit of render functions over templates?
1497
-
In VueJS, the templates are very powerful and recommended to build HTML part of your application. However, some of the special cases like dynamic component creation based on input or slot value can be achieved through render functions. Also, these functions gives the full programmatic power of javascript eco system.
1498
+
In VueJS, the templates are very powerful and recommended to build HTML as part of your application. However, some of the special cases like dynamic component creation based on input or slot value can be achieved through render functions. Also, these functions gives the full programmatic power of javascript eco system.
1498
1499
69. ### What is a render function?
1499
1500
Render function is a normal function which receives a `createElement` method as it’s first argument used to create virtual nodes. Internally Vue.js' templates actually compile down to render functions at build time. Hence templates are just syntactic sugar of render functions. Let's take an example of simple Div markup and corresponding render function,
1500
1501
The HTML markup can be written in template tag as below,
@@ -1508,11 +1509,13 @@ List of 300 VueJS Interview Questions
1508
1509
and the compiled down or explicit render function would appear as below,
1509
1510
```javascript
1510
1511
render: function (createElement) {
1511
-
returncreateElement('div',
1512
-
{ 'class': {
1513
-
'is-rounded':this.isRounded
1514
-
}
1515
-
},[ createElement('p', 'Welcome to Vue render functions')])
1512
+
returncreateElement('div', {
1513
+
'class': {
1514
+
'is-rounded':this.isRounded
1515
+
}
1516
+
}, [
1517
+
createElement('p', 'Welcome to Vue render functions')
1518
+
]);
1516
1519
},
1517
1520
```
1518
1521
**Note:** The react components are built with render functions inJSX.
@@ -1521,12 +1524,14 @@ List of 300 VueJS Interview Questions
1521
1524
```javascript
1522
1525
// @returns {VNode}
1523
1526
createElement(
1524
-
// An HTML tag name, component options, or async function resolving to one of these. Required.
1527
+
// An HTML tag name, component options, or async function resolving to one of these.
1525
1528
// Type is {String | Object | Function}
1529
+
// Required.
1526
1530
'div',
1527
1531
1528
-
// A data object corresponding to the attributes you would use in a template. Optional.
1532
+
// A data object corresponding to the attributes you would use in a template.
1529
1533
//Type is {Object}
1534
+
// Optional.
1530
1535
{
1531
1536
// Normal HTML attributes
1532
1537
attrs: {
@@ -1557,8 +1562,9 @@ List of 300 VueJS Interview Questions
1557
1562
....
1558
1563
},
1559
1564
1560
-
// Children VNodes, built using `createElement()`, or using strings to get 'text VNodes'. Optional.
1565
+
// Children VNodes, built using `createElement()`, or using strings to get 'text VNodes'.
1561
1566
// Type is {String | Array}
1567
+
// Optional.
1562
1568
[
1563
1569
'Learn about createElement arguments.',
1564
1570
createElement('h1', 'Headline as a child virtual node'),
@@ -1570,6 +1576,7 @@ List of 300 VueJS Interview Questions
1570
1576
]
1571
1577
)
1572
1578
```
1579
+
see details of the date object in official [doc](https://vuejs.org/v2/guide/render-function.html#The-Data-Object-In-Depth).
1573
1580
71. ### How can you write duplicate virtual nodes in a component?
1574
1581
All virtual nodes(VNodes) in the component tree must be unique.i.e, You can't write duplicated nodes in a straightforward way. If you want to duplicate the same element/component many times then you should use factory function.
1575
1582
The below render function is invalid where you are trying to duplicate h1 element 3 times,
0 commit comments