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}}
对前端的技术,架构技术感兴趣的同学关注我的头条号,并在后台私信发送关键字:“前端”即可获取免费的架构师学习资料
知识体系已整理好,欢迎免费领取。还有面试视频分享可以免费获取。关注我,可以获得没有的架构经验哦!!
閱讀更多 前端全棧架構丶 的文章
關鍵字: 状态 下面 ECMAScript