1

I'm trying to put in an array('allData') 2 array of objects from 'roomContent' and 'roomSurveys. And when i check with vue inspector my allData is well created but not filled with the elements I want...

My goal is to display the components (post-card and answer-card which are components) thanks to a array(allData) that I can handle but for that I have to insert in this array the post and survey's data with mapState.

here is my script:

import { mapState } from 'vuex'
import AnswerCard from '~/components/Answers/AnswerCard'
import PostCard from '~/components/Content/PostCard'
// // import DecodedTagInHour from '~/components/Graphics/DecodedTagInHour'
// import DecodedTagMap from '~/components/Map/DecodedTagMap'

export default {
  name: 'ContentDisplay',
  components: {
    AnswerCard,
    PostCard,
    // DecodedTagInHour,
    // DecodedTagMap
  },
  computed: {
    ...mapState('surveys', ['roomSurveys']),
    ...mapState('post', ['roomContent']),
    
  },
  mounted() {
    this.allData.push(...this.roomSurveys, ...this.roomContent)
  },
  data() {
    return {
      allData: [],
    }
  }, 

here is my template :

 <div v-for="data in allData" :key="data.id">
        <post-card v-if="data.type === 'post'"
          >
        </post-card>
        <answer-card  v-if="data.type === 'survey'">
        </answer-card>
      </div> 

and like u can see my array contains nothing : vue inspector

7
  • i dont need of mapGetters because like u can see I already get my elements with mapState
    – lucastoni
    Commented May 5, 2021 at 9:31
  • You can edit the question to add more info in it, instead of comments
    – T J
    Commented May 5, 2021 at 9:35
  • What's inside <post-card> shouldn't you be passing some data as props to it?
    – T J
    Commented May 5, 2021 at 9:36
  • i update my post thx for the tips and i answered to ur question in my post @TJ
    – lucastoni
    Commented May 5, 2021 at 9:43
  • If your project is in GitHub, importing it (or a simplified version) into CodeSandbox would help for analysis.
    – Tim
    Commented May 5, 2021 at 14:30

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.