nuxt-community/nuxt-property-decorator

Name: nuxt-property-decorator

Owner: Nuxt Community

Description: Property decorators for Nuxt (base on vue-property-decorator)

Created: 2017-09-07 12:56:55.0

Updated: 2018-05-19 08:43:41.0

Pushed: 2018-04-12 17:03:13.0

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

Size: 145

Language: TypeScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Nuxt Property Decorator

npm

This library fully depends on nuxt-class-component.

License

MIT License

Install
i -S nuxt-property-decorator
Usage

There are 6 decorators:

rt { Component, Inject, Model, Prop, Vue, Watch } from 'nuxt-property-decorator'

t s = Symbol('baz')

ponent
rt class MyComponent extends Vue {

nject() foo: string
nject('bar') bar: string
nject(s) baz: string

odel('change') checked: boolean

rop()
opA: number

rop({ default: 'default value' })
opB: string

rop([String, Boolean])
opC: string | boolean

rop({ type: null })
opD: any

rovide() foo = 'foo'
rovide('bar') baz = 'bar'

atch('child')
ChildChanged(val: string, oldVal: string) { }

atch('person', { immediate: true, deep: true })
PersonChanged(val: Person, oldVal: Person) { }

is equivalent to

t s = Symbol('baz')

rt const MyComponent = Vue.extend({
me: 'MyComponent',
ject: {
foo: 'foo',
bar: 'bar',
[s]: s

del: {
prop: 'checked',
event: 'change'

ops: {
checked: Boolean,
propA: Number,
propB: {
  type: String,
  default: 'default value'
},
propC: [String, Boolean],
propD: { type: null }

ta () {
return {
  foo: 'foo',
  baz: 'bar'
}

ovide () {
return {
  foo: this.foo,
  bar: this.baz
}

thods: {
onChildChanged(val, oldVal) { },
onPersonChanged(val, oldVal) { }

tch: {
'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.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.