Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

super() in a method overriden via Vue.extend #2977

Closed
cybertino opened this issue May 30, 2016 · 10 comments
Closed

super() in a method overriden via Vue.extend #2977

cybertino opened this issue May 30, 2016 · 10 comments

Comments

@cybertino
Copy link

It would be great to have super() method available to be able to call parent implementation.

@cybertino cybertino changed the title super() in overriden method via extend super() in a method overriden via Vue.extend May 30, 2016
@yyx990803
Copy link
Member

  1. This won't be implemented in Vue.js core because I don't want to endorse deep class inheritance.
  2. You can use this.constructor.super.options.methods.method.call(this) - this is obviously super verbose, but you can easily write a helper to shorten it to something like callSuper(this, 'methodName').

@rpkilby
Copy link

rpkilby commented Jun 1, 2016

Hi @softomatix - I wrote vue-super, which might be helpful.

@druppy
Copy link

druppy commented Jun 1, 2016

Sorry, to keep answering into a closed thread :-(

I really like to known more about why Vue are not using ES6 classes, besides "I don't want to endorse deep class inheritance".

I agree that "deep inheritance" is not a god thing to encourage, but that is not a really good argument for not using ES6 classes more directly.

Some times ago, You wrote something about static properties that would be a problem in native classes, what else could be a problem, and could there be found a solution ?

Would it be possible to have a Vue.extend type and ES6 class in parallel, to make a more natural integration to both ES6 and Typescript ? As I wrote before, this is the single most strange thing about Vue, and I really like all the rest a lot !

/BL

@simplesmiler
Copy link
Member

@druppy classes are not awesome.
Also, #2371 (comment) and #2371 (comment).

@druppy
Copy link

druppy commented Jun 2, 2016

Ok, that was an interesting read, I understand the reason better now ... So I guess vue-class-component will enable static type checking in ts (I can fake data types in the class declaration), and the rest could be a good idea to reconsider (inheritance in this case).

@phil294
Copy link

phil294 commented Oct 27, 2018

Fyi, The syntax specified by @yyx990803 does not seem to be valid anymore. this.constructor.super.options does not contain a methods property (using extends: MyComp syntax).

Using MyComp.methods.... instead. Works but not as clean.

@milworm
Copy link

milworm commented Oct 28, 2018

  1. This won't be implemented in Vue.js core because I don't want to endorse deep class inheritance.
  2. You can use this.constructor.super.options.methods.method.call(this) - this is obviously super verbose, but you can easily write a helper to shorten it to something like callSuper(this, 'methodName').

@yyx990803 It's not about deep class inheritance, it's about using "extends" property according to how it's done everywhere and how it is described in the docs. Are you planning to remove "extends" in future releases of vue?

@hrobertson
Copy link

Slight modification to @phil294 's MyComp.methods...: I found I needed MyComp.options.methods...

export default {
  name: 'MyComponent',
  extends: OtherComponent,
  methods: {
    foo() {
      let value = OtherComponent.options.methods.foo.call(this);
      // do your thing, modify value, etc
      return value;
    },
  },
};

@likemusic
Copy link

likemusic commented Jun 23, 2021

vue-just-super - my implementation for call super() in child inherited components (both by extends and mixins options).

It allows you to call parent component's method just by this.$super(...arguments) in child component's method (and also in mixin's methods).

@xuanWangisAlibaba19960403
Copy link

xuanWangisAlibaba19960403 commented Oct 21, 2022

vue-super-options - It allows you to call parent component's method just by this.$supermethodName in child component's method

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants