Answer the question
In order to leave comments, you need to log in
Why is it impossible to mold 2 received arrays into 1?
I write this code:
Vue:
data() {
return {
info: null,
users: null
};
},
mounted() {
this.axios
.get("https://jsonplaceholder.typicode.com/posts")
.then(response => (this.info = response.data));
this.axios
.get("https://jsonplaceholder.typicode.com/users")
.then(response => (this.users = response.data));
},
computed: {
fullArray() {
return this.info.concat(this.users)
}
}
<div id="app">
{{fullArray}}
<div>
<ul>
<li class="box" v-for="(item,index) in info" :key="item.id">{{info[index].body}}</li>
</ul>
<ul>
<li class="users" v-for="(user,index) in users" :key="user.id">{{users[index].name}}</li>
</ul>
</div>
</div>
TypeError: Cannot read property 'concat' of nulland does not render the component at all. If you remove computed, then everything, of course, renders well. I'm trying to make a test task
Answer the question
In order to leave comments, you need to log in
Because at first the component is displayed, and then the data comes. And at the moment of the first fullArray UPD calculation
Add a check, something like this:this.info === null
fullArray() {
const arr = []
if (this.info) arr.concat(this.info)
if (this.users) arr.concat(this.users)
return arr
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question