Vue Messenger
A series of useful enhancements to Vue components props:
Install
Package
CDN
Available as global VueMessenger
.
Usage
Install mixin
Globally
Locally
Transform props
To transform a prop, add a transform: value => transformedValue
function to its descriptor, and use this.local${PropName}
to get transformed prop. e.g.
? before
? after
Enum-type props
To define a enum-type prop, add a enum
array to its descriptor, and its default
value will be enum[0]
if the descriptor doesn't contain default
attribute. e.g.
? before
? after
Numeric-type props
To define a numeric-type prop, add numeric: true
to its descriptor. Besides, you can set infinite
to ture
to allow infinite numbers, which are -Infinity
and Infinity
. e.g.
? before
? after
Listen for receiving props
To listen for receiving a prop, add on: { receive: (newValue, oldValue) => void }
object to its descriptor. e.g.
? before
? after
Two-way data binding props
To apply two-way data bindings on a prop, add sync: true
to its descriptor. Then, you can use this.local${PropName} = newValue
or this.send${PropName}(newValue)
to send new value to Parent component.
If the prop is model prop, it's no need to add
sync: true
to its descriptor.