本文整理匯總了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 }
})
}