options.d.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import { Vue, CreateElement } from "./vue";
  2. import { VNode, VNodeData, VNodeDirective } from "./vnode";
  3. type Constructor = {
  4. new (...args: any[]): any;
  5. }
  6. export type Component = typeof Vue | ComponentOptions<Vue> | FunctionalComponentOptions;
  7. interface EsModuleComponent {
  8. default: Component
  9. }
  10. export type AsyncComponent = (
  11. resolve: (component: Component) => void,
  12. reject: (reason?: any) => void
  13. ) => Promise<Component | EsModuleComponent> | Component | void;
  14. export interface ComponentOptions<V extends Vue> {
  15. data?: Object | ((this: V) => Object);
  16. props?: string[] | { [key: string]: PropOptions | Constructor | Constructor[] };
  17. propsData?: Object;
  18. computed?: { [key: string]: ((this: V) => any) | ComputedOptions<V> };
  19. methods?: { [key: string]: (this: V, ...args: any[]) => any };
  20. watch?: { [key: string]: ({ handler: WatchHandler<V, any> } & WatchOptions) | WatchHandler<V, any> | string };
  21. el?: Element | String;
  22. template?: string;
  23. render?(this: V, createElement: CreateElement): VNode;
  24. renderError?: (h: () => VNode, err: Error) => VNode;
  25. staticRenderFns?: ((createElement: CreateElement) => VNode)[];
  26. beforeCreate?(this: V): void;
  27. created?(this: V): void;
  28. beforeDestroy?(this: V): void;
  29. destroyed?(this: V): void;
  30. beforeMount?(this: V): void;
  31. mounted?(this: V): void;
  32. beforeUpdate?(this: V): void;
  33. updated?(this: V): void;
  34. activated?(this: V): void;
  35. deactivated?(this: V): void;
  36. directives?: { [key: string]: DirectiveOptions | DirectiveFunction };
  37. components?: { [key: string]: Component | AsyncComponent };
  38. transitions?: { [key: string]: Object };
  39. filters?: { [key: string]: Function };
  40. provide?: Object | (() => Object);
  41. inject?: { [key: string]: string | symbol } | string[];
  42. model?: {
  43. prop?: string;
  44. event?: string;
  45. };
  46. parent?: Vue;
  47. mixins?: (ComponentOptions<Vue> | typeof Vue)[];
  48. name?: string;
  49. extends?: ComponentOptions<Vue> | typeof Vue;
  50. delimiters?: [string, string];
  51. comments?: boolean;
  52. inheritAttrs?: boolean;
  53. }
  54. export interface FunctionalComponentOptions {
  55. name?: string;
  56. props?: string[] | { [key: string]: PropOptions | Constructor | Constructor[] };
  57. inject?: { [key: string]: string | symbol } | string[];
  58. functional: boolean;
  59. render(this: never, createElement: CreateElement, context: RenderContext): VNode | void;
  60. }
  61. export interface RenderContext {
  62. props: any;
  63. children: VNode[];
  64. slots(): any;
  65. data: VNodeData;
  66. parent: Vue;
  67. injections: any
  68. }
  69. export interface PropOptions {
  70. type?: Constructor | Constructor[] | null;
  71. required?: boolean;
  72. default?: any;
  73. validator?(value: any): boolean;
  74. }
  75. export interface ComputedOptions<V> {
  76. get?(this: V): any;
  77. set?(this: V, value: any): void;
  78. cache?: boolean;
  79. }
  80. export type WatchHandler<V, T> = (this: V, val: T, oldVal: T) => void;
  81. export interface WatchOptions {
  82. deep?: boolean;
  83. immediate?: boolean;
  84. }
  85. export type DirectiveFunction = (
  86. el: HTMLElement,
  87. binding: VNodeDirective,
  88. vnode: VNode,
  89. oldVnode: VNode
  90. ) => void;
  91. export interface DirectiveOptions {
  92. bind?: DirectiveFunction;
  93. inserted?: DirectiveFunction;
  94. update?: DirectiveFunction;
  95. componentUpdated?: DirectiveFunction;
  96. unbind?: DirectiveFunction;
  97. }