使用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的名字', 参数)
vuex的使用可参考:vue中使用vuex(超详细) - 掘金 (juejin.cn)