【问题标题】:Laravel and Vue - handler.call is not a functionLaravel 和 Vue - handler.call 不是函数
【发布时间】:2020-04-26 18:31:29
【问题描述】:

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

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

[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)
            }
        }
    }

【问题讨论】:

  • 添加创建的方法而不是像created() { }这样的属性

标签: php laravel vue.js


【解决方案1】:

你用正确的方式编写了mounted(),但是创建的函数定义是错误的。缺少第一个括号。

 created: {

    }

 //change it to

 created() {

    }

【讨论】:

    【解决方案2】:

    请更改

    created() {
    ...
    }
    

    created=() =>{
    ...
    }
    

    【讨论】:

      猜你喜欢
      • 2019-10-26
      • 2018-12-18
      • 2019-04-08
      • 2017-06-20
      • 2023-02-14
      • 2021-03-14
      • 2019-02-15
      • 2017-08-21
      • 2017-07-09
      相关资源
      最近更新 更多