Vue 2 - Uncaught TypeError: cloned[i].apply is not a function at HTMLInputElement.invoker (vue.esm.js?65d7:1810) error

回眸只為那壹抹淺笑 提交于 2020-01-14 03:43:08

问题


I am getting the error from the title:

Uncaught TypeError: cloned[i].apply is not a function
    at HTMLInputElement.invoker (vue.esm.js?65d7:1810)

Made standard setup with vue-cli (simple webpack), and this is my component:

<template>
    <div class="column is-4">
        <nav class="panel">
            <p class="panel-heading">
                Authors in our library
            </p>

            <div class="panel-block">
                <p class="control has-icons-left">
                    <input class="input is-small" type="text" placeholder="Search"
                        v-model="search"
                        @keyup="filterAuthors">
                        <span class="icon is-small is-left">
                        <i class="fa fa-search"></i>
                    </span>
                </p>
            </div>

            <a class="panel-block is-active" v-for="author in filterAuthors">
                <span class="panel-icon">
                  <i class="fa fa-book"></i>
                </span>
                {{ author }}
            </a>

        </nav>
    </div>
</template>

<script>

    export default {
        data () {
            return {
                'search' : ''
            }
        },
        computed: {
            filterAuthors() {
                let search = this.search.toLowerCase();

                return this.$store.state.authors.filter((author) => {
                    return author.toLowerCase().indexOf(search) >= 0;
                })


            }
        }
    }

</script>

Strange part is that the filter is working, but every time I type into the input field, I get this error. Anyone have any idea what can it be?


回答1:


Computed properies are reactive by default, and in fact you can't attach them to event handler.

Removing the keyup event handler that calls computed property should fix the problem.

            <p class="control has-icons-left">
                <input class="input is-small" type="text" placeholder="Search">
                    <span class="icon is-small is-left">
                    <i class="fa fa-search"></i>
                </span>
            </p>



回答2:


For some reason, I had a property name under data and a function with the same name under methods.

Removing the property fixed a similar error.

new Vue({
    el: '#elem',
    data: {
      function_name: null,  // <- removed this
    },
    methods: {
      function_name: function() {
        // ...
      }
    }
});


来源:https://stackoverflow.com/questions/45349800/vue-2-uncaught-typeerror-clonedi-apply-is-not-a-function-at-htmlinputelemen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!