vuex

1.实现组件之间数据共享

2.核心概念:State   Mutation Action  Getter

其中 State是存储共享数据的;Mutation 是用来修改State中共享数据;Action是处理异步函数的,所有异步任务例如axios都要卸载active中;Getter是用来包装State中的数据的。

3.State的使用:

  方式一:this.$store.state.数据名

  方式二:import {mapState} from 'vuex'  在computed中展开 --- ...mapState(['数据名']) 在页面中直接使用数据名就可以

4.Mutation的使用:

  方式一:this.$store.commit('函数名’)触发

  方式二:import {mapMutations} from 'vuex'   在method中展开 ...mapMutations(['函数名'])在页面中 用this.$store.commit('函数名’)触发函数

5.Active的使用

  方式一:this.$store.dispatch('函数名') 触发

  方式二:  import {mapActives} from 'vuex' 在method中展开 ...mapActives(['函数名‘)] 就可直接使用该函数,触发this.$store.dispatch('函数名’)

6.Getter的使用:

  方式一: this.$store.getters.数据名

  方式二:import {mapGetters} from 'vuex' 在computed中展开 ...mapGetters(['函数名‘])就可直接使用 一般情况getter有返回值。

7.弹窗

this.$message.warning("内容")

posted @ 2021-09-09 21:33  冰镇汽水  阅读(29)  评论(0编辑  收藏  举报