[Vuejs]-How to get state vuex on mounted() and pass to data?

0👍

once you have loaded data from getNames, you can then easily mirror the state in the component with mapState:

computed: {
  ...mapState('namesAll', state => state.namesAll)
},

0👍

You can use mapGetters of vuex.
This is a example:

vuex


const state = {
  names: {
    all: []
  }
}

const getters = {
  nameAll: state => state.name.all
}

view.vue

<template>
  <span>{{ nameAll }}</span>
</template>
<script>
import { mapGetters } from 'vuex'
export default {
  computed: {
    ...mapGetters(['nameAll'])
  }
}
</script>

Leave a comment