TypeError: Unable to read the "replace" property from undefined vue-resource.js: 284

Can anyone help me with this error?

I use jQuery along with vue.js. Below is the method I am facing ... It is called by mail request. new_usercontains the values ​​obtained from the fields of the html form ...

The values ​​are obtained beautifully when I write it in the console.

The problem occurs when I try to use the ajax method to store data (this is. $ Http.post ()). I get the following error:

TypeError: Unable to read replace property from undefinedView-resource.js: 284

There were several links I went through. But I could help anyone ... I might have made stupid mistakes because I used the above code from a perfectly working script. Therefore, if anyone can spot a mistake, I would be grateful. Thank...:)

Happy coding.

    addUser : function(new_user){
        // var instance = this;
        console.log(this)
        var new_user_input = this.new_user
        console.log(new_user_input.name)//this works fine..

         //problem comes right here
         this.$http.post("clients/" , new_user_input).then((response) => {
            alert("ok")
        },(response) => {
            alert("failed")
            this.form_errors = response.data
            // console.log("here should be the form errrors " + response.data.title)
        });
    }
+4
source share
1 answer

If you are using Laravel, make sure you have a template:

Good:

<script>
        window.Laravel = <?php echo json_encode([
            'csrfToken' => csrf_token(),
        ]); ?>
</script>

//OR

<script>
    window.Laravel = {!! json_encode([
        'csrfToken' => csrf_token(),
    ]) !!}
</script>

BADLY:

<script>
        window.Laravel = '<?php echo json_encode([
            'csrfToken' => csrf_token(),
        ]); ?>'
</script>

//OR

<script>
    window.Laravel = {{ json_encode([
        'csrfToken' => csrf_token(),
    ]) }}
</script>
+1
source

Source: https://habr.com/ru/post/1657504/


All Articles