Question 91
How do you configure vuejs in webpack?
You can configure vueJS in webpack using alias as below,
module.exports = {
// ...
resolve: {
alias: {
'vue$': 'vue/dist/vue.esm.js' // 'vue/dist/vue.common.js' for webpack 1
}
}
}
Question 91
You can configure vueJS in webpack using alias as below,
module.exports = {
// ...
resolve: {
alias: {
'vue$': 'vue/dist/vue.esm.js' // 'vue/dist/vue.common.js' for webpack 1
}
}
}
Question 92
The compiler is is responsible for compiling template strings into JavaScript render functions.
For example, the below code snippet shows the difference of templates which need compiler and not,
// this requires the compiler
new Vue({
template: '<div>{{ message }}</div>'
})
// this does not
new Vue({
render (h) {
return h('div', this.message)
}
})
Question 93
DevTools is a browser extension allowing you to inspect and debug your Vue applications in a more user-friendly interface. You can find the below extensions for different browsers or environments,
The DevTools plugins can be used as shown in the below snapshot,
Note:
file:// protocol, you need to check "Allow access to file URLs" for this
extension in Chrome's extension management panel.Question 94
It supports all ECMAScript5 complaint browsers as mentioned in this url. VueJS doesn't support IE8 browser and below, because it uses ECMAScript 5 features that are un-shimmable(require support from the underlying JS engine) in IE8.
Question 95
VueJS is available in jsdelivr, unpkg and cdnjs etc CDNs. Normally you can use them for prototyping or learning purposes.
For example, you can use them using jsdelivr with latest versions as below,
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.7/dist/vue.js"></script>
You can use it for native ES modules as below,
<script type="module">
import Vue from 'https://cdn.jsdelivr.net/npm/vue@2.6.7/dist/vue.esm.browser.js'
</script>
Note: You can remove version number to get latest version.
Question 96
It is extremely rare situation of having to manually force an update despite the fact that no reactive data has changed. i.e, To force the Vue instance to re-render manually. You can do it force update using **vm.$forceUpdate() ** API method.
Note: It does not affect all child components but only the instance itself and child components with inserted slot content.
Question 97
If you want to render a lot of static content then you need to make sure it only evaluated once and then cached
thereafter. In this case, you can use v-once directive by wrapping at the root level.
The example usage of v-once directive would be as below,
Vue.component('legal-terms', {
template: `
<h1>Legal Terms</h1>
... a lot of static content goes here...
`
})
Note: It is recommended not to overuse unless there is slow rendering due to lot of static content.
Question 98
The root instance(new Vue()) can be accessed with the $root property.
Let's see the usage of root instance with an example.
First let's create a root instance with properties and methods as below,
// The root Vue instance
new Vue({
data: {
age: 26
},
computed: {
fullName: function () { /* ... */ }
},
methods: {
interest: function () { /* ... */ }
}
})
Now you can access root instance data and it's methods with in subcomponents as below,
// Get root data
this.$root.age
// Set root data
this.$root.age = 29
// Access root computed properties
this.$root.fullName
// Call root methods
this.$root.interest()
It is recommend using Vuex to manage state instead of using root instance as a global store.
Question 99
Below are the top 10 organizations using VueJS for their applications or products,
Question 100
When the default render function encounters an error then you can use rennderError as an alternative render output. The error will be passed to renderError as the second argument.
The example usage of renderError is as below,
new Vue({
render (h) {
throw new Error('An error')
},
renderError (h, err) {
return h('div', { style: { color: 'red' }}, err.stack)
}
}).$mount('#app')
Question 101
The $parent object refers to the immediate outer scope. The parent will be accessible as
this.$parent for the child, and the child will be pushed into the parent's $children array. It establishes a
parent-child relationship between the two instances(parent and child). You can access parent data and properties
similar to $root.
Question 102
Vuex is a state management pattern + library (Flux-inspired Application Architecture) for Vue.js applications. It serves as a centralized store for all the components in an application, with rules ensuring that the state can only be mutated in a predictable fashion.
Question 103
The state management has state, view and actions as major components. The pattern followed by these components in a application is known as State Management Pattern. Below are the components in a detail,
Let us take a counter example which follows state management pattern with the above 3 components,
new Vue({
// state
data () {
return {
count: 0
}
},
// view
template: `
`,
// actions
methods: {
increment () {
this.count++
}
}
})
Question 104
Vue.js has a one-way data flow model, through the props property. The same concept can be represented in vuex has below,
Question 105
Vue loader is a loader for webpack that allows you to author Vue components in a format called Single-File Components (SFCs).
For example, it authors HelloWorld component in a SFC,
<template>
</template>
<script>
export default {
data () {
return {
message: 'Hello world for vueloader!'
}
}
}
</script>
<style>
.greeting {
color: blue;
}
</style>