count {{$store.state.count}}
```
每个组件(也就是`Vue实例`)在`beforeCreate`的生命周期中都混入(Vue.mixin)同一个`Store实例` 作为属性 `$store`,
也就是为啥可以通过 `this.$store.dispatch` 等调用方法的原因。
最后显示在模板里的
`$store.state.count`
源码是这样的。
```js
class Store{
get state () {
return this._vm._data.$$state
}
}
```
其实就是:
`vm.$store._vm._data.$$state.count`
其中`vm.$store._vm._data.$$state` 是 响应式的。
怎么实现响应式的?其实就是`new Vue()`
```js
function resetStoreVM (store, state, hot) {
// 省略若干代码
store._vm = new Vue({
data: {
$$state: state
},
computed
})
// 省略若干代码
}
```
这里的 `state` 就是 用户定义的 `state`。
这里的 `computed` 就是处理后的用户定义的 `getters`。
而 `class Store`上的一些函数(API)主要都是围绕修改`vm.$store._vm._data.$$state`和`computed(getter)`服务的。
## 3. Vue.use 安装
笔者画了一张图表示下`Vuex`对象,是`Vue`的一个插件。

>看到这里,恭喜你已经了解了`Vuex`原理。文章比较长,如果暂时不想关注源码细节,可以克隆一下本仓库代码`git clone https://github.com/lxchuan12/vuex-analysis.git`,后续调试代码,点赞收藏到时想看了再看。
[文档 Vue.use](https://cn.vuejs.org/v2/api/#Vue-use)
`Vue.use(Vuex)`
>参数:
>{Object | Function} plugin
>用法: