这次给大家带来怎样操作vuex的state状态对象,操作vuex的state状态对象的注意事项有哪些,下面就是实战案例,一起来看一下。
vuex是一个专门为vue.js设计的状态管理模式,并且也可以使用devtools进行调试。
下面给大家来贴一下我的vuex的结构
下面是store文件夹下的state.js和index.js内容
//state.js
const state = {
headerBgOpacity:0,
loginStatus:0,
count:66
}
export default state
//index.js
import Vue from 'vue'
import Vuex from 'vuex'
import state from './state'
import actions from './actions'
import getters from './getters'
import mutations from './mutations'
Vue.use(Vuex)
export default new Vuex.Store({
state,
actions,
getters,
mutations
})下面开始在test.vue组件当中使用vuex的state状态对象
方式一
{{$store.state.count}}
方式二
{{count}}
方式三
{{count}}
方式四
{{count}}
方式五
{{count}}
相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!
推荐阅读:










