samedi 25 novembre 2017

Vuejs and Vuex actions - Request failed with status code 422

Hi and thanks for any help! I'm creating a system comment with Laravel 5.5, Vue 2 and Vuex. I Can't post a comment. I get in my console, two errors:

TypeError: this.addComment is not a function

Error: Request failed with status code 422

This is my code:

import { addComment } from '../../store/actions
export default {
  computed: {
    addComment
  },
  vuex: {
    actions: { addComment }
  },
  data () {...},
  methods: {
    sendComment: function () {
        this.addComment({
            commentable_id: this.id,
            commentable_type: this.model,
            content: this.content,
            reply: this.reply
        })
    }

actions.js code

export const addComment = function ({dispatch}, comment) {
    return axios.post('/comments', comment).then((response) => {
        dispatch('ADD_COMMENT', response.data)
    })
};

All my routes, controller and mutations are tested and work well



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire