vuex学习笔记

当我们需要一个常量,在各个组件中传播,当用户开了几个窗口进行操作时,会存在数据污染,导致部分无法访问

vuex引入控制中心,将公用的数据放在一起,其余要改的则要询问,若同意更改则可以

核心数据库中心

vuex适合中大型项目

新建store.js

import Vue from 'vue'

import Vuex from 'vuex'

Vue.use(Vuex)

const state ={

      count:4

}

export default new vuex.Store({})

state访问状态对象

mutations访问触发状态

       

})

vuex.vue

<template>

      <div id="app">

           <h1>Hello Vuex</h1>

           <p>{{$store.state.count}}</p>

           <p>

                <button></button>

           </p>

       </div>

</template>

</template>

原文地址:https://www.cnblogs.com/yiyiyurou/p/7816714.html