vuex 思维笔记

2022-01-17  本文已影响0人  charmingcheng
Vuex.png

mapGetters辅助函数的使用

<script>
import { mapGetters } from 'vuex'
...

export default {
  components: {
    ...
  },
  computed: {
    ...mapGetters([
      'sidebar',
      'avatar'
    ])
  },
  methods: {
    toggleSideBar() {
      this.$store.dispatch('app/toggleSideBar')
    },
    async logout() {
      await this.$store.dispatch('user/logout')
      this.$router.push(`/login?redirect=${this.$route.fullPath}`)
    }
  }
}
</script>

上一篇 下一篇

猜你喜欢

热点阅读