Reputation: 3903
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?
Upvotes: 0
Views: 151
Reputation: 3903
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!
Upvotes: 1
Reputation: 2347
you do not need 'this' in the data properties:
props: {
mydata: {
type: Array,
default: []
}
}
data(){
arrayList: []
}
created(){
this.arrayList = this.$props.mydata;
}
Upvotes: 0