作者:我爱你可你不懂_516 | 来源:互联网 | 2023-09-24 18:42
In the inheritance chain mixins are placed before a component, which implies that any constructor in
should be called before the constructor of a component. E.g.:
mixin.ts:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| import Vue from `'vue';
import Component from 'vue-class-component';
export interface AwesomeMixinInterface {
aProp: string;
method( something: string ): void;
}
export class AwesomeMixin extends Vue implements AwesomeMixinInterface {
public aProp: string;
constructor() {
super();
this.aProb = '';
console.log( 'a' );
}
public method( something: string ) {
this.aProb = something;
}
} |
component.vue:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| |
I expect that the rendered text of the
should be 'something' and the console.log order should 'a', 'b'. But
is empty and the order of the console.log is 'b', 'a'.
Using:
vue : 2.5.21 ,
vue-class-component : 6.3.2 ,
typescript : 3.2.2
该提问来源于开源项目:vuejs/vue-class-component
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| ts
import Vue from 'vue'
import Component from 'vue-class-component'
({
})
export default class BaseVue extends Vue {
constructor(){
super()
console.log("BaseVue init")
}
} |
when rendering "MyComp" ,the subclass is constructed before the parent class.