vue vuex公共状态管理

官网说,vue是单一状态树,所有的状态数据都在这统一管理。

// 第一步: vuex 是vue的插件,不是自带的

npm install vuex --save




//第二步: main.js 挂载到dom上

import App from 'app.vue'
import store from '@/store'

new Vue({
    store,
    render: h => h(App) 
}).$mount("#app")




//第三步: store.js入口

import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)

import state from './state'
import mutations from './mutations'
import actions from './actions'

const store = new Vuex.store({
    state,
    mutations,
    actions
})
export default store

分模块写store:

//第三步: store.js入口

import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)

import state from './state'
import mutations from './mutations'
import actions from './actions'

const store = new Vuex.store({
    state,
    mutations,
    actions
})
export default store


一个store文件
----------------------------------------------------
多个store文件


import module from './module' // module文件包含多个export
// export { default as p } from '..' export { default as d } from '..'

new Vuex.store({
    module
})

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值