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状态对象
方式一
<template>
{{$store.state.count}}
/<template>
方式二
<template>
{{count}}
/<template>
方式三
<template>
{{count}}
/<template>
方式四
<template>
{{count}}
/<template>
方式五
<template>
{{count}}
/<template>
閱讀更多 劉弋 的文章
關鍵字: 状态 下面 ECMAScript