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>
閱讀更多 劉弋 的文章