Reputation: 55
Im trying to get the value of classlists into my uScore but it's giving me an error.
How can i pass the value of method displayClasslists
to uScore
methods: {
displayClasslists() {
this.$Progress.start();
axios
.get("/api/labview/" + this.$route.params.placeName)
.then(({ data }) => this.$Progress.finish((this.classlists = data)));
},
uScore: function() {
const elements = this.classlists.map(e => e.id);
console.log(elements);
}
},
this is what i get:
[Vue warn]: Error in mounted hook: "TypeError: this.classlists.map is not a function"
This is my json classlists
Upvotes: 1
Views: 40
Reputation: 64312
Here are a some suggestions:
uScore
doesn't take any arguments and it depends only on classlists
, then it should probably be a computed property.uScore
doesn't return anything.classlists
to be an empty array to avoid the error.export default {
data() {
return { classlists: [] };
},
computed: {
uScore() {
return this.classlists.map(e => e.id);
},
},
methods: {
displayClasslists() {
this.$Progress.start();
axios.get(`/api/labview/${this.$route.params.placeName}`).then(({ data }) => {
this.classlists = data;
this.$Progress.finish();
});
},
},
};
Upvotes: 3