0

In my vue-application I want to assign prop data to an arraylist.

<MyComponent :mydata="someArrayData" />

In "MyComponent" I want to do this:

props: {
   mydata: {
      type: Array,
      default: []
   }
}
data(){
   arrayList: []
}
created(){
   this.arrayList = this.$props.mydata;
}

but then "this.arrayList" is empty - when I do console.log(this.$props.mydata) it returns the data.

what am I doing wrong here?

1
  • Isn't there an error in the console telling you "data functions should return an object"? Your data function doesn't return anything Commented Jan 27, 2021 at 10:56

2 Answers 2

1

I actually managed to solve it by simply adding:

<div v-if="someArrayData.length">
   <MyComponent :mydata="someArrayData" />
</div>

now it works for me!

Thanks for the help anyway!

Sign up to request clarification or add additional context in comments.

Comments

0

you do not need 'this' in the data properties:

props: {
   mydata: {
      type: Array,
      default: []
   }
}
data(){
   arrayList: []
}
created(){
   this.arrayList = this.$props.mydata;
}

1 Comment

ah sorry, my bad - I actually didnt have "this" in the data properties - updated my question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.