Skip to content

[BUG] Metadata defined on a component can't be retreived from a mixin #536

Open
@amura11

Description

@amura11

I wanted to create a decorator that would add metadata to my class component then be able to pull that metadata out using a mixin and the beforeCreate hook (I'm not sure if that's the right term). However, when the method runs and I try to get the metadata the metadata isn't there. Looking at the source for this library I saw a function that looks like it would copy the metadata (this file) which makes me think it should be possible.

Code
My code is much more complex than this but it boils down to essentially this:

const metadataKey: string = "myMetadataKey";

function MyDecorator(token: string) {
    return (target: any, property: string) => {
        Reflect.defineMetadata(metadataKey, token, target);
    };
}

@Component
export default class MyView extends Vue {
	
	@MyDecorator("test")
	private myProperty!: string;
}

Vue.mixin({
	beforeCreate() {
		console.log(Reflect.getMetadata(metadataKey, this)); //This doesn't work for me
	}
});

Is this something I can even achieve?

P.S. I'm not sure if this is even related to this library or Vue itself, this seemed like the best place to start

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