Skip to content

Commit 427efe7

Browse files
committed
Add vue cli features
1 parent 7db926b commit 427efe7

File tree

1 file changed

+105
-14
lines changed

1 file changed

+105
-14
lines changed

README.md

Lines changed: 105 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,13 @@ List of 300 VueJS Interview Questions
200200
|191| [What is the versioning behavior in preset plugins?](#what-is-the-versioning-behavior-in-preset-plugins)|
201201
|192| [How do you allow plugin prompts?](#how-do-you-allow-plugin-prompts)|
202202
|193| [What are remote presets?](#what-are-remote-presets)|
203-
|194| [](#)|
204-
|195| [](#)|
205-
|196| [](#)|
206-
|197| [](#)|
207-
|198| [](#)|
208-
|199| [](#)|
209-
|200| [](#)|
203+
|194| [Can I use local presets?](#can-i-use-local-presets)|
204+
|195| [What is the purpose of browserslist option?](#what-is-the-purpose-of-browserslist-option)|
205+
|196| [How do you find VueJS version using API?](#how-do-you-find-vuejs-version-using-api)|
206+
|197| [How do you create reactive objects](#how-do-you-create-reactive-objects)|
207+
|198| [What is the purpose new slot directive?](#what-is-the-purpose-new-slot-directive)|
208+
|199| [What is the use of compile method?](#what-is-the-use-of-compile-method)|
209+
|200| [What does nextTick do in VueJS?](#what-does-nexttick-do-in-vuejs)|
210210

211211
1. ### What is VueJS?
212212
**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.
@@ -3401,12 +3401,103 @@ List of 300 VueJS Interview Questions
34013401
# use preset from GitHub repo
34023402
vue create --preset username/repo my-project
34033403
```
3404-
194. ### ?
3405-
195. ### ?
3406-
196. ### ?
3407-
197. ### ?
3408-
198. ### ?
3409-
199. ### ?
3410-
200. ### ?
3404+
194. ### Can I use local presets?
3405+
Yes, Vue CLI will load local presets if the value for the --preset option is a relative or absolute file path, or ends with .json. i.e, You can work with local presets directly. These local presets avoids repeatedly pushing the preset to a remote repo to test.
3406+
```javascript
3407+
// Directory contains preset.json file
3408+
vue create --preset ./my-preset my-project
3409+
(OR)
3410+
vue create --preset my-preset.json my-project
3411+
```
3412+
195. ### What is the purpose of browserslist option?
3413+
The browserslist option is available in package.json file in order to specify a range of browsers the project is supported. This value is going to be used by babel and autoprefixer to transpile javascript features and applying vendor prefixes.
3414+
For example, you can declare it as follows,
3415+
```javascript
3416+
"browserslist": [
3417+
"last 1 version",
3418+
"> 1%",
3419+
"IE 10"
3420+
]
3421+
```
3422+
196. ### How do you find VueJS version using API?
3423+
The community plugins and components might need different strategies for different versions. In this case, you can use **Vue.version** which provides installed version of Vue as a string.
3424+
For example, you can implement different logic based on different versions
3425+
```javascript
3426+
let version = Number(Vue.version.split('.')[0])
3427+
3428+
if (version === 2) {
3429+
// Vue v2.x.x
3430+
} else if (version === 1) {
3431+
// Vue v1.x.x
3432+
} else {
3433+
// Unsupported versions of Vue
3434+
}
3435+
```
3436+
197. ### How do you create reactive objects?
3437+
From 2.6 version onwards, you can create reactive objects with Vue.observable() global API.
3438+
```javascript
3439+
const reactiveState = Vue.observable({
3440+
count: 0
3441+
})
3442+
```
3443+
These observable objects can be used directly in computed properties and render functions.
3444+
```javascript
3445+
const Demo = {
3446+
render(h) {
3447+
return h('button', {
3448+
on: { click: () => { reactiveState.count++ }}
3449+
}, `count is: ${state.count}`)
3450+
}
3451+
}
3452+
```
3453+
198. ### What is the purpose new slot directive?
3454+
In Vue 2.6 version, the new slot syntax is provided using v-slot directive which aligns syntax with Vue 3.0. This is going to be replacement for old slot syntax.
3455+
The comparison for old and new slot syntax:
3456+
```javascript
3457+
<!-- old -->
3458+
<user>
3459+
<template slot="header" slot-scope="{ msg }">
3460+
text slot: {{ msg }}
3461+
</template>
3462+
</user>
3463+
3464+
<!-- new -->
3465+
<user>
3466+
<template v-slot:header="{ msg }">
3467+
text slot: {{ msg }}
3468+
</template>
3469+
</user>
3470+
```
3471+
199. ### What is the use of compile method?
3472+
VueJS provides compile method which is used to compile a template string into a render function. This method is only available in the full build.
3473+
For example, you can compile template message:
3474+
```javascript
3475+
var result = Vue.compile('<div><span>{{ msg }}</span></div>')
3476+
3477+
new Vue({
3478+
data: {
3479+
msg: 'Welcome to Vue world'
3480+
},
3481+
render: result.render,
3482+
staticRenderFns: result.staticRenderFns
3483+
})
3484+
```
3485+
200. ### What does nextTick do in VueJS?
3486+
The nextTick method is just a comfortable way to execute a function after the data has been set, and the DOM has been updated. As an example, the usage is going to be similar to setTimeout:
3487+
```javascript
3488+
// modify data
3489+
vm.msg = 'Welcome to Vue'
3490+
// DOM not updated yet
3491+
Vue.nextTick(function () {
3492+
// DOM updated
3493+
})
3494+
3495+
// usage as a promise (2.1.0+)
3496+
Vue.nextTick()
3497+
.then(function () {
3498+
// DOM updated
3499+
})
3500+
```
3501+
34113502
201. ### ?
34123503

0 commit comments

Comments
 (0)