未捕获的类型错误:升级到 vue 3.x 时无法读取未定义的属性(读取“深”)

Dol*_*hin 14 javascript vuejs3

将vue升级到3.x后,控制台显示如下错误:

Uncaught TypeError: Cannot read properties of undefined (reading 'deep')
    at withDirectives (commons1.js:10679:17)
    at Proxy.render (eval at compileToFunction (commons1.js:40198:21), <anonymous>:36:7)
    at renderComponentRoot (commons1.js:7874:44)
    at ReactiveEffect.componentUpdateFn [as fn] (commons1.js:11968:57)
    at ReactiveEffect.run (commons1.js:5819:29)
    at setupRenderEffect (commons1.js:12094:9)
    at mountComponent (commons1.js:11877:9)
    at processComponent (commons1.js:11835:17)
    at patch (commons1.js:11436:21)
    at render (commons1.js:12579:13)
Run Code Online (Sandbox Code Playgroud)

我不知道发生了什么,认为这可能是一个兼容问题。我不知道如何找到哪里出了问题。我不知道输出js中哪里出了问题(从这个错误中我不知道源代码哪里出了问题),代码如下:

/**
 * Adds directives to a VNode.
 */
function withDirectives(vnode, directives) {
    const internalInstance = currentRenderingInstance;
    if (internalInstance === null) {
        ( true) && warn(`withDirectives can only be used inside render functions.`);
        return vnode;
    }
    const instance = internalInstance.proxy;
    const bindings = vnode.dirs || (vnode.dirs = []);
    for (let i = 0; i < directives.length; i++) {
        let [dir, value, arg, modifiers = _vue_shared__WEBPACK_IMPORTED_MODULE_1__.EMPTY_OBJ] = directives[i];
        if ((0,_vue_shared__WEBPACK_IMPORTED_MODULE_1__.isFunction)(dir)) {
            dir = {
                mounted: dir,
                updated: dir
            };
        }
        // here throw the error message
        if (dir.deep) {
            traverse(value);
        }
        bindings.push({
            dir,
            instance,
            value,
            oldValue: void 0,
            arg,
            modifiers
        });
    }
    return vnode;
}
Run Code Online (Sandbox Code Playgroud)

当运行到dir.deep线路时,抛出这个错误,我应该做什么来解决这个问题?我尝试从谷歌搜索似乎没有人面临同样的问题。

小智 13

我今天遇到了这个问题,我发现问题是因为我试图使用未注册的指令。

如果您在错误发生之前的调用处放置一个断点,在您的情况下, at Proxy.render (eval at compileToFunction (commons1.js:40198:21), <anonymous>:36:7) 您会发现类似的内容const _directive_focus = _resolveDirective("focus");,然后您就知道缺少什么指令


eyl*_*lay 7

当您输入错误时,错误消息会产生误导!

对我来说这是 v-model 中的一个拼写错误

<input type="text" class="form-control" v-moel="newUser.name">
Run Code Online (Sandbox Code Playgroud)

在我将拼写错误修正为 后v-moelv-model它就得到了修复。

另一次我遇到这个错误是因为再次输入错误:

<div v-esle class="alert alert-warning">
    ...
</div>
Run Code Online (Sandbox Code Playgroud)

所以结论是,在检查其他任何内容之前,请确保您没有拼写错误

  • @DMonkey 其他人可能会像我一样有拼写错误,因为在这些情况下错误消息会产生误导 (5认同)