npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nuxt-property-decorator

v2.9.1

Published

Property decorators for Nuxt

Downloads

104,716

Readme

Nuxt Property Decorator

Handy ES / TypeScript decorators for class-style Vue components in Nuxt (based on Vue class component) and Property decorators for Vue (bases on Vue Property Decorator) and Vuex (based on Vuex Class)

This library fully depends on vue-class-component.

License

MIT License

Install

Installation is very easy

npm i -S nuxt-property-decorator

or

yarn add nuxt-property-decorator

Nuxt JS Instructions

It works out of the box with Nuxt JS.

Nuxt TS Instructions

It works out of the box with Nuxt TS.

Decorators and helpers

There are following decorators:

Other exports

  • namespace
  • mixins
  • Vue

Hooks

Vue Router hooks

  • beforeRouteEnter
  • beforeRouteUpdate
  • beforeRouteLeave

Nuxt hooks

  • asyncData
  • fetch
  • fetchOnServer
  • head
  • key
  • layout
  • loading
  • middleware
  • scrollToTop
  • transition
  • validate
  • watchQuery
  • meta

Vue-class Hooks

  • data
  • beforeCreate
  • created
  • beforeMount
  • mounted
  • beforeDestroy
  • destroyed
  • beforeUpdate
  • updated
  • activated
  • deactivated
  • render
  • errorCaptured
  • serverPrefetch

Usage

import {
  Component,
  Inject,
  Model,
  Prop,
  Provide,
  Vue,
  Watch,
} from "nuxt-property-decorator"

const s = Symbol("baz")

@Component({
  components: { comp },
})
export class MyComponent extends Vue {
  @Inject() foo!: string
  @Inject("bar") bar!: string
  @Inject(s) baz!: string

  @Model("change") checked!: boolean

  @Prop()
  propA!: number

  @Prop({ default: "default value" })
  propB!: string

  @Prop([String, Boolean])
  propC!: string | boolean

  @Prop({ type: null })
  propD!: any

  @Provide() foo = "foo"
  @Provide("bar") baz = "bar"

  @Watch("child")
  onChildChanged(val: string, oldVal: string) {}

  @Watch("person", { immediate: true, deep: true })
  onPersonChanged(val: Person, oldVal: Person) {}

  beforeRouteLeave(to, from, next) {
    // called when the route that renders this component is about to
    // be navigated away from.
    // has access to `this` component instance.
  }
}

is equivalent to

const s = Symbol("baz")

export const MyComponent = Vue.extend({
  name: "MyComponent",
  components: { comp },
  inject: {
    foo: "foo",
    bar: "bar",
    [s]: s,
  },
  model: {
    prop: "checked",
    event: "change",
  },
  props: {
    checked: Boolean,
    propA: Number,
    propB: {
      type: String,
      default: "default value",
    },
    propC: [String, Boolean],
    propD: { type: null },
  },
  data() {
    return {
      foo: "foo",
      baz: "bar",
    }
  },
  provide() {
    return {
      foo: this.foo,
      bar: this.baz,
    }
  },
  methods: {
    onChildChanged(val, oldVal) {},
    onPersonChanged(val, oldVal) {},
  },
  beforeRouteLeave(to, from, next) {
    // called when the route that renders this component is about to
    // be navigated away from.
    // has access to `this` component instance.
  },
  watch: {
    child: {
      handler: "onChildChanged",
      immediate: false,
      deep: false,
    },
    person: {
      handler: "onPersonChanged",
      immediate: true,
      deep: true,
    },
  },
})

As you can see at propA and propB, the type can be inferred automatically when it's a simple type. For more complex types like enums you do need to specify it specifically. Also this library needs to have emitDecoratorMetadata set to true for this to work.

Useful links

See also: