使用vuex

1、安装: npm i vuex  (yarn add vuex)

2、使用:

  1.新建store文件夹,在下面新建index.js文件,作为store文件的总出口。

 

 

 

  2.在main.js文件中引入store文件夹,在vue中使用。

 

3.vue文件使用store

获取数据:this.$store.state.tab.isCollapse
修改数据:this.$store.commit('mutation事件名',mapper参数)
调用异步请求action:this.$store.dispatch('actions的名字', 参数)

 

posted @ 2022-08-07 11:55  银河1992  阅读(33)  评论(0编辑  收藏  举报