vue-property-decorator

repository·master·Indexed 26 days ago

https://github.com/kaorun343/vue-property-decorator

A deprecated library providing TypeScript decorators for Vue.js components to enable a class-based programming model. It allows defining props, watchers, provides, injects, and emits using decorators such as @Prop, @Watch, @Provide, @Inject, @Emit, and @Ref. Version 9.1.2 depends on vue-class-component.

Tokens
875
Snippets
1
Records
12
Agent score
90%

What's inside vue-property-decorator

  1. Emit custom events with the @Emit decorator

    master

    Use the @Emit decorator to automatically emit Vue component events when a method is called.

    By default, the emitted event name is the kebab-case version of the method name. If you provide a string argument to @Emit(eventName), that specific name will be used instead.

    Behavioral Rules:

    • Event Naming: If no event name is provided, the method name is hyphenated (e.g., myMethod becomes my-method).
    • Arguments:
      • If the method returns undefined and has no arguments, it emits the event without payload.
      • If the method returns undefined and has arguments, it emits the event with those arguments.
      • If the method returns a value, that value is automatically prepended to the arguments list sent to $emit.
    • Async Support: If the decorated method returns a Promise, the event will be emitted only after the promise resolves, using the resolved value as the event payload.
  2. Inject dependencies using the @Inject decorator

    master

    Use the @Inject decorator to inject dependencies into a Vue component via the inject option.

    You can provide the injection key directly, or pass an options object to specify a different key to use for the injection (from) or a default value.

    Arguments:

    • options (optional): An object of type InjectOptions or an InjectKey.
      • from: The specific key to use for the injection.
      • default: The default value to use if the dependency is not found.
    • key (required): The property name on the class where the injected dependency will be assigned.
  3. Use the @InjectReactive decorator

    master
    The @InjectReactive decorator allows you to inject a reactive dependency into a Vue component. It works by injecting a key (internally using reactiveInjectKey) and then creating a computed property with the same name as the decorated property. This computed property resolves to the value of the injected object's specific key, ensuring reactivity is maintained.