Skip to content

Vue.extend and constructor chain #2409

@druppy

Description

@druppy

First, thanks for sharing this really nice and powerful tool !

I have tried to make use of ES6 or Typescript classes for new components, especially to gain some static testing for TS. I have played with the vue-class-decorator, and it all seems quite OK, except for one thing, the constructor chain.

class TestComp extends Vue {
   n = 42;
   constructor() {
      console.log( "we never end here, and this ", n, " is undefined" );
   }
   data() {return{ "test":42};}
}

var i = TestComp.extend({template:'<div>{{test}}</div>'});

This is, in the eyes of Vue, what the decorator does (in addition, it moves some functions and data around, but that is beside the point), when defining new components.

But in order to make this work as a normal class, we need to be able to call the constructor of the classes, and when this is done the Vue.extend() applied constructor should not call Vue._init() anymore (as the constructor of the Vue class does this), but let the normal constructor chain handle that.

I have looked into 'Vue.extend()' and it seems like some Super class awareness are there, but as far as I can see it end up in only forcing a single call to the 'Vue._init()' function, and nothing more happens.

So are there a trick to make a control constructor behavior in a extended class, or is this on the todo list ?

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