Skip to content

组件通信

🕒 Published at:

组件通信

vuex

js
Vue.use(Vuex),new vuex.store产生一个store,传入new vue的配置对象的store项中,
vuex有6个配置项,modules,namespaced,mutations,actions,state,getters
组件中通过mapState,mapgetters,mapMutations,mapActions等封装方法
也可以用this.$store获取store状态

3中通过createStore创建,任意vue文件中useStore即可

pinia

js
通过definePinia创建useStore,用的地方引入调用useStore得到store去使用