Vue. JS

Par SoBaDayz, il y a 8 ans


Bonjour,

Voila je rencontre un petit problème avec mon code.

Ce que je fais

Voilà j'ai une erreur avec mon code, l'erreur est Uncaught (in promise) TypeError: nots.body.forEach is not a function

Voici mon code:

export default { mounted() { this.get_unread() }, methods: { get_unread() { this.$http.get('/get_unread') .then( (nots) => { nots.body.forEach((not) => { this.$store.commit('add_not', not) }) }) } }, computed: { all_nots_count() { return this.$store.getters.all_nots_count } } }

Je vous remercie.

1 réponse

betaWeb, il y a 8 ans

Salut,

L'erreur est pourtant explicite : l'objet nots n'a pas de méthode forEach, ce qui signifie que ce n'est pas un array JavaScript valide.

Fais un console.log(nots) pour voir de quoi il en retourne :

this.$http .get('/get_unread') .then(console.log)