vue-property-decorator
Version:
property decorators for Vue Component
22 lines (21 loc) • 712 B
JavaScript
import { createDecorator } from 'vue-class-component';
/**
* decorator for capturings v-model binding to component
* @param options the options for the prop
*/
export function VModel(options) {
if (options === void 0) { options = {}; }
var valueKey = 'value';
return createDecorator(function (componentOptions, key) {
;
(componentOptions.props || (componentOptions.props = {}))[valueKey] = options;
(componentOptions.computed || (componentOptions.computed = {}))[key] = {
get: function () {
return this[valueKey];
},
set: function (value) {
this.$emit('input', value);
},
};
});
}