Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
89 views
in Technique[技术] by (71.8m points)

javascript - Vue how to assign prop data to arraylist

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?

question from:https://stackoverflow.com/questions/65917405/vue-how-to-assign-prop-data-to-arraylist

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...