Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel and Vue - handler.call is not a function

Trying to create a small application to show some news, but can't figure this error out. What am I doing wrong?

I'am trying to show the news one at a time by visually "sliding" through the news. The application runs and work, but still shows this error:

[Vue warn]: Error in created hook: "TypeError: handler.call is not a function"

Template:

<template>
    <div>
        <div class="a_news" v-for="aNews in news">
        <span v-show="true">
            <h1 class="title" v-text="aNews.title"></h1>
            <div class="text" v-text="aNews.text"></div>
            <div class="aNews_image"><img v-bind:src="aNews.images[0]"/></div>
        </span>
        </div>
    </div>
</template>

Script:

export default {
        data() {
            return {
                news: [],
            }
        },
        computed: {

        },
        created: {

        },
        mounted() {
            this.getData(false, 0);
        },
        methods: {
            getData(oldnum, num) {

                const CORS_PROXY = "https://cors-anywhere.herokuapp.com/";
                axios.get(CORS_PROXY + 'URL').then(resp => {
                    console.log(resp.data);
                    this.news.push(resp.data.slides[num]);
                });
                setTimeout(function () {
                    if(oldnum == false) {
                        oldnum = num;
                    }
                    if(oldnum >= 0) {
                        oldnum = num;
                        num = num +1
                    }
                    this.news = [];
                    if(num >= 8) {
                        this.getData(false,0)
                    }else{
                        this.getData(oldnum,num)
                    }

                }.bind(this), 25000)
            }
        }
    }
like image 881
Martin Hartmann Avatar asked Jan 09 '20 07:01

Martin Hartmann


Video Answer


2 Answers

You wrote mounted() in the right way, but the created function definition is wrong. 1st brackets missing.

 created: {

    }

 //change it to

 created() {

    }
like image 159
Tamzid Oronno Avatar answered Sep 29 '22 19:09

Tamzid Oronno


please change

created() {
...
}

OR

created=() =>{
...
}
like image 28
kelvin kantaria Avatar answered Sep 29 '22 18:09

kelvin kantaria