vue-property-decorator
Version:
property decorators for Vue Component
27 lines (26 loc) • 1.02 kB
JavaScript
import { createDecorator } from 'vue-class-component';
import { applyMetadata } from '../helpers/metadata';
/**
* decorator of a synced prop
* @param propName the name to interface with from outside, must be different from decorated property
* @param options the options for the synced prop
* @return PropertyDecorator | void
*/
export function PropSync(propName, options) {
if (options === void 0) { options = {}; }
return function (target, key) {
applyMetadata(options, target, key);
createDecorator(function (componentOptions, k) {
;
(componentOptions.props || (componentOptions.props = {}))[propName] = options;
(componentOptions.computed || (componentOptions.computed = {}))[k] = {
get: function () {
return this[propName];
},
set: function (value) {
this.$emit("update:" + propName, value);
},
};
})(target, key);
};
}