16

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)
            }
        }
    }
1
  • add created method not property like created() { } Commented Jan 9, 2020 at 7:37

2 Answers 2

18

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

 created: {

    }

 //change it to

 created() {

    }
Sign up to request clarification or add additional context in comments.

Comments

4

please change

created() {
...
}

OR

created=() =>{
...
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.