Laravel 和 Vue - handler.call 不是函数

试图创建一个小应用程序来显示一些新闻,但无法弄清楚这个错误。我究竟做错了什么?


我试图通过视觉“滑动”新闻来一次显示一个新闻。应用程序运行并工作,但仍显示此错误:


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

模板:


<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>

脚本:


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)

            }

        }

    }



蛊毒传说
浏览 99回答 2
2回答

守着一只汪

您以正确的方式编写了mounted(),但是创建的函数定义是错误的。第一个括号丢失。&nbsp;created: {&nbsp; &nbsp; }&nbsp;//change it to&nbsp;created() {&nbsp; &nbsp; }

子衿沉夜

请更换created() {...}或者created=() =>{...}
打开App,查看更多内容
随时随地看视频慕课网APP