Skip to content

FormItem中当定义自定义directive时报错 #972

@wd2010

Description

@wd2010
  • I have searched the issues of this repository and believe that this is not a duplicate.

Version

1.3.10

Environment

macOS10.14 chrome75 Vue2.6.10

Reproduction link

Edit on CodeSandbox

Steps to reproduce

// 自定义组件  HelloWorld.vue
<a-form :form="form">
<a-form-item>
<a-input v-decorator="['inputValue']"/>
</a-form-item>
</a-form>
// 父组件 自定义directive
<template>
<a-form :form="form">
<a-form-item>
<hello-world v-clearData></hello-world>
</a-form-item>
</a-form>
</template>
// FormItem.js
function decoratorOption(vnode) {
if (vnode.data && vnode.data.directives) {
var directive = find(vnode.data.directives, ['name', 'decorator']);  // 取到的directive为undefined,因为此时的directives是包含 自定义组件v-clearData的

warning(!directive || directive && Array.isArray(directive.value), 'Invalid directive: type check failed for directive "decorator". Expected Array, got '   _typeof(directive.value)   '. At '   vnode.tag   '.'); // 导致directive.value报错

return directive ? directive.value : null;
} else {
return null;
}
}

What is expected?

warning(!directive || directive && Array.isArray(directive.value), 'Invalid directive: type check failed for directive "decorator". Expected Array, got '   _typeof(directive.value)   '. At '   vnode.tag   '.');

期望当directive为undefined时,_typeof(directive.value) 做兼容

What is actually happening?

TypeError: Cannot read property 'value' of undefined at VueComponent.decoratorOption


在全局定义了自定义directive时

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions