Skip to content

The extends option behavior is same with mixins #7412

Closed
@ustbhuangyi

Description

@ustbhuangyi

Version

2.5.13

Reproduction link

https://codesandbox.io/s/x7non3yrj4

Steps to reproduce

See the console

What is expected?

CompB created

CompA created

What is actually happening?

CompA created

CompB created


As the Doc says, extends option is similar to mixins, the difference being that the components own options takes higher priority than the source component being extended.
However, the fact is that the source component being extended has higher priority, which is same with mixins.

See the source code of Vue.js

export function mergeOptions (
  parent: Object,
  child: Object,
  vm?: Component
): Object {
  // ...
  const extendsFrom = child.extends
  if (extendsFrom) {
    parent = mergeOptions(parent, extendsFrom, vm)
  }
  if (child.mixins) {
    for (let i = 0, l = child.mixins.length; i < l; i  ) {
      parent = mergeOptions(parent, child.mixins[i], vm)
    }
  }
  // ...
}

I think the logic of extends and mixins is almost the same.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions