Laravel:未捕获(承诺)错误:请求失败,状态码为422

时间:2020-03-06 08:12:59

标签: javascript php sql laravel axios

enter image description here enter image description here

您好,目前我正面临这个问题。我能修好他。我不知道为什么会发生错误。

基本上,我试图将数据保存到DB中。我使用了Axios方法来获取和保存数据。在此之前,该功能运行良好,但突然导致了问题。拜托,任何人都可以帮助我。

Vue.js

<script>
    import Vue from 'vue'
    import axios from 'axios'
    import VueAxios from 'vue-axios' 

    import MarkdownIt from 'markdown-it'
    import ClassicEditor from '@ckeditor/ckeditor5-build-classic';
    var msg_editor;
    Vue.use(VueAxios, axios);


    const md = new MarkdownIt({
        linkify: true
    })
// Vue.directive('select2', {
//         inserted(el) {
//             $(el).on('select2:select', () => {
//                 const event = new Event('change', { bubbles: true, cancelable: true });
//             el.dispatchEvent(event);
//         });
//         },
//     });
//  $('#condition').select2();




  export default {
    props: ['email_creation_link', 'email_index_route', 'email_edit_route','conditions','modules','mailtemplates'],

    components: {


    },


    data() {
        return {
            template: 
             {
                subject: '',
                message: '' ,
                days: '',
                condition_id: 1,

            },
            options:[
                {
                    display:'Client Name',
                    actual:'Client name'
                }, 
                {
                    display:'Joined Date',
                    actual:'Joined date'
                },
                {
                    display:'Module Name',
                    actual:'Module name'
                },
                {
                    display:'Last Seen',
                    actual:'Last seen'
                },
            ],


              showName: false,



        }
    },




    mounted(){


            var self = this;

            ClassicEditor
            .create(document.querySelector( "#msg"),
                {
                })
            .then(editor => {
                msg_editor = editor;
                editor.model.document.on( 'change:data', () => {
                    self.template.message = msg_editor.getData();
                });
            })

            .catch(error => {
                console.error(error);
            })


            if (this.mailtemplates) {
                    this.template=this.mailtemplates;

            }



        }, 


    methods: {



        //Drag items
        dragstart: function(item, e){
            this.draggingItem = item;
            e.dataTransfer.setData('text/plain', item.actual);
        },
        dragend: function(item,e) {
            e.target.style.opacity = 1;
        },
        dragenter: function(item, e) {
            this.draggingItem = item;
        },
        //content
        replaceVariables(input)
        {
            let updated = input
            return updated
        },
        //hidecontent
        showHide: function(e)
        {

            console.log("Show "+e.target.value+ " fields")
            this.showName = e.target.value == '3'


        },

        fetch()
        {
            //request data
            axios.get(this.email_creation_link,this.template)
                .then((res) => {
                    this.template = res.data.template;

                })

        },
        save()
        {
            //save data to db
            axios.post(this.email_creation_link, this.template)
                .then((res) => {
                    alert('Mail sent successfull!')
                })
        },
        addToMail: function(type, text)
        {
            if (type == 'message') {
                this.template.message += text;
                msg_editor.setData(this.template.message);
            }
        },

        //user name replace
        replaceVariables() {
            return this.replaceVariables(this.options || '')
        },
    },


  }
</script>

route.php

  Route::post('api/email/create', ['as' => 'email.create', 'uses' => 'Havence\AutoMailController@create']);
    Route::get('automail/mail',['as'=>'email.mail','uses' => 'Havence\AutoMailController@mail']);
    Route::get('automail/index',['as'=>'email.index','uses' => 'Havence\AutoMailController@index']);
    Route::get('automail/edit/{id}',['as'=>'email.edit','uses' => 'Havence\AutoMailController@edit']);
    Route::get('automail/delete',['as'=>'email.delete','uses' => 'Havence\AutoMailController@destroy']);

0 个答案:

没有答案