vue-coerce-props
Version:
Coerce props to custom values
20 lines (17 loc) • 403 B
JavaScript
export default {
beforeCreate () {
const { props } = this.$options
if (!props) return
this._$coertions = Object.keys(props)
.filter(k => props[k].coerce)
.map(k => [k, props[k].coerce])
},
computed: {
$coerced () {
return this._$coertions.reduce((c, [k, coerce]) => {
c[k] = coerce.call(this, this.$props[k])
return c
}, {})
},
},
}