[Vuejs]-Laravel/Vue form Validation

3👍

Item is already an object so you dont need it to put in an object variable and the name it item.

Change your axios request to:

methods: {
        addItem() {
            // if (this.item.name === "") {
            //     return;
            // }
            axios
                .post("api/item/store", this.item)
                .then(response => {
                    if (response.status == 201) {
                        this.item.name = "";
                        this.$emit("reloadlist");
                        this.errors = {};
                    }
                })
                .catch(error => {
                    if (error.response.status == 422) {
                        this.errors = error.response.data.errors;
                    }
                    console.log(error);
                });
        }
    }

I think this will solve your problem.

👤Japs

Leave a comment