本文整理汇总了TypeScript中vue-class-component.createDecorator函数的典型用法代码示例。如果您正苦于以下问题:TypeScript createDecorator函数的具体用法?TypeScript createDecorator怎么用?TypeScript createDecorator使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了createDecorator函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: Option
/**
* decorator of model
* @param {any} value option value
* @return {Function} VueDecorator
*/
export default function Option(value): Function {
return createDecorator((componentOptions: Record<string, any>, k) => {
if (!componentOptions.options) {
componentOptions.options = {};
}
componentOptions.options[k] = value;
});
}
示例2: Watch
export function Watch(path: string, options: WatchOptions = {}): MethodDecorator {
const { deep = false, immediate = false } = options
return createDecorator((componentOptions, handler) => {
if (typeof componentOptions.watch !== 'object') {
componentOptions.watch = Object.create(null)
}
(componentOptions.watch as any)[path] = { handler, deep, immediate }
})
}
示例3: Inject
export function Inject(options?: { from?: InjectKey, default?: any } | InjectKey): PropertyDecorator {
return createDecorator((componentOptions, key) => {
if (typeof componentOptions.inject === 'undefined') {
componentOptions.inject = {}
}
if (!Array.isArray(componentOptions.inject)) {
componentOptions.inject[key] = options || key
}
})
}
示例4: Provide
export function Provide(key?: string | symbol): PropertyDecorator {
return createDecorator((componentOptions, k) => {
let provide: any = componentOptions.provide
if (typeof provide !== 'function' || !provide.managed) {
const original = componentOptions.provide
provide = componentOptions.provide = function (this: any) {
let rv = Object.create((typeof original === 'function' ? original.call(this) : original) || null)
for (let i in provide.managed) rv[provide.managed[i]] = this[i]
return rv
}
provide.managed = {}
}
provide.managed[k] = key || k
})
}
示例5: Prop
export function Prop(options: (PropOptions | Constructor[] | Constructor) = {}): PropertyDecorator {
return createDecorator((componentOptions, k) => {
(componentOptions.props || (componentOptions.props = {}) as any)[k] = options
})
}
示例6: Model
export function Model(event?: string, options: (PropOptions | Constructor[] | Constructor) = {}): PropertyDecorator {
return createDecorator((componentOptions, k) => {
(componentOptions.props || (componentOptions.props = {}) as any)[k] = options
componentOptions.model = { prop: k, event: event || k }
})
}