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
+89Lines changed: 89 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -149,6 +149,13 @@ List of 300 VueJS Interview Questions
149
149
|140|[Can I use strict mode in production environment?](#can-i-use-strict-mode-in-production-environment)|
150
150
|141|[What is vuex plugin?](#what-is-vuex-plugin)|
151
151
|142|[How do you mutate state in plugins?](#how-do-you-mutate-state-in-plugins)|
152
+
|143|[What is vuex store?](#what-is-vuex-store)|
153
+
|144|[What are the differences of vuex store and plain global object?](#what-are-the-differences-of-vuex-store-and-plain-global-object)|
154
+
|145|[What is the reason not to update the state directly?](#what-is-the-reason-not-to-update-the-state-directly)|
155
+
|146|[What is Single state tree?](#what-is-single-state-tree)|
156
+
|147|[How do you install vuex?](#how-do-you-install-vuex)|
157
+
|148|[Do I need promise for vuex?](#do-i-need-promise-for-vuex)|
158
+
|149|[How do you display store state in vue components?](#how-do-you-display-store-state-in-vue-components)|
152
159
153
160
1.### What is VueJS?
154
161
**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.
@@ -2654,4 +2661,86 @@ List of 300 VueJS Interview Questions
2654
2661
mutations,
2655
2662
plugins: [plugin]
2656
2663
})
2664
+
```
2665
+
143. ### What is vuex store?
2666
+
A Vuex "store" is basically a container that holds your application state. The store creation is pretty straightforward.
2667
+
Below are the list of instructions to use vuex in an increment application,
2668
+
1. Configure vuex in vuejs ecosystem
2669
+
```javascript
2670
+
import Vuex from "vuex";
2671
+
Vue.use(Vuex)
2672
+
```
2673
+
2. Provide an initial state object and some mutations
2674
+
```javascript
2675
+
// Make sure to call Vue.use(Vuex) first if using a module system
2676
+
2677
+
const store = new Vuex.Store({
2678
+
state: {
2679
+
count: 0
2680
+
},
2681
+
mutations: {
2682
+
increment (state) {
2683
+
state.count++
2684
+
}
2685
+
}
2686
+
})
2687
+
```
2688
+
3. Trigger state change with commit and access state variables,
2689
+
```javascript
2690
+
store.commit('increment')
2691
+
2692
+
console.log(store.state.count) // -> 1
2693
+
```
2694
+
144. ### What are the differences of vuex store and plain global object?
2695
+
Below are the two major differences between vuex store and plain global object
2696
+
1. **Vuex stores are reactive:** If the store's state changes then vue components will reactively and efficiently get updated
2697
+
2. **Cannot directly mutate the store's state:** The store's state is changed by explicitly committing mutations to ensure that every state change leaves a track-able record for tooling purpose
2698
+
145. ### What is the reason not to update the state directly?
2699
+
We want to explicitly track application state in order to implement tools that can log every mutation, take state snapshots, or even perform time travel debugging. So we need to commit a mutation instead of changing store's state directly.
2700
+
146. ### What is Single state tree?
2701
+
Vuex's single state tree is single object contains all your application level state and serves as the "single source of truth". It does not conflict with modularity when you split state and mutations into sub modules.
2702
+
147. ### How do you install vuex?
2703
+
You can install vuex using npm or yarn as below,
2704
+
```javascript
2705
+
npm install vuex --save
2706
+
(or)
2707
+
yarn add vuex
2708
+
```
2709
+
In a module system, you must explicitly install Vuex via Vue.use()
2710
+
```javascript
2711
+
import Vue from 'vue'
2712
+
import Vuex from 'vuex'
2713
+
2714
+
Vue.use(Vuex)
2715
+
```
2716
+
(OR)
2717
+
You can also install it using CDN links such as unpkg.cpm which provides NPM-based CDN links. Just include vuex after Vue and it will install itself automatically.
2718
+
```javascript
2719
+
<script src="https://unpkg.com/vue.js"></script>
2720
+
<script src="https://unpkg.com/vuex.js"></script>
2721
+
```
2722
+
**Note:** You can use a specific version/tag via URLs like https://unpkg.com/vuex@2.0.0. If you don't mention any version then it will point to latest version.
2723
+
148. ### Do I need promise for vuex?
2724
+
Yes, Vuex requires Promise. If your supporting browsers do not implement Promise (e.g. IE), you can use a polyfill library, such as es6-promise using npm or yarn.
2725
+
```javascript
2726
+
npm install es6-promise --save # NPM
2727
+
yarn add es6-promise # Yarn
2728
+
```
2729
+
After that import into anywhere in your application,
2730
+
```javascript
2731
+
import 'es6-promise/auto'
2732
+
```
2733
+
149. ### How do you display store state in vue components?
2734
+
Since Vuex stores are reactive, you can retrieve" state from store by simply returning store's state from within a computed property. i.e, Whenever store state changes, it will cause the computed property to re-evaluate, and trigger associated DOM updates.
2735
+
Let's take a hello word component which display store's state in the template,
0 commit comments