首页 > 解决方案 > Vue 3 和 Mixin:this.$el.querySelectorAll 不是函数

问题描述

当我尝试这个时:

createApp(App).mixin({
    methods: {
        myFunction() {
            this.$el.querySelectorAll('input').forEach(...);
        }
    },

    mounted() {
        this.myFunction();
    }
}).mount('#app');

我得到了一个TypeError: this.$el.querySelectorAll is not a function但奇怪的是一切都按预期工作。所以 this.$el 被定义,querySelectorAll() 返回节点,我可以用 forEach() 遍历它们。这里有什么问题,我该如何摆脱错误?

标签: javascriptvue.jstypeerrormixinsvuejs3

解决方案


推荐阅读