options.d.ts 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import { Vue } from "./vue";
  2. import { VNode, VNodeData, VNodeDirective } from "./vnode";
  3. type Constructor = {
  4. new (...args: any[]): any;
  5. }
  6. type $createElement = typeof Vue.prototype.$createElement;
  7. export interface ComponentOptions<V extends Vue> {
  8. data?: Object | ((this: V) => Object);
  9. props?: string[] | { [key: string]: PropOptions | Constructor | Constructor[] };
  10. propsData?: Object;
  11. computed?: { [key: string]: ((this: V) => any) | ComputedOptions<V> };
  12. methods?: { [key: string]: Function };
  13. watch?: { [key: string]: ({ handler: WatchHandler<V> } & WatchOptions) | WatchHandler<V> | string };
  14. el?: Element | String;
  15. template?: string;
  16. render?(this: V, createElement: $createElement): VNode;
  17. staticRenderFns?: ((createElement: $createElement) => VNode)[];
  18. beforeCreate?(this: V): void;
  19. created?(this: V): void;
  20. beforeDestroy?(this: V): void;
  21. destroyed?(this: V): void;
  22. beforeMount?(this: V): void;
  23. mounted?(this: V): void;
  24. beforeUpdate?(this: V): void;
  25. updated?(this: V): void;
  26. directives?: { [key: string]: DirectiveOptions | DirectiveFunction };
  27. components?: { [key: string]: ComponentOptions<Vue> | FunctionalComponentOptions | typeof Vue };
  28. transitions?: { [key: string]: Object };
  29. filters?: { [key: string]: Function };
  30. parent?: Vue;
  31. mixins?: (ComponentOptions<Vue> | typeof Vue)[];
  32. name?: string;
  33. extends?: ComponentOptions<Vue> | typeof Vue;
  34. delimiters?: [string, string];
  35. }
  36. export interface FunctionalComponentOptions {
  37. props?: string[] | { [key: string]: PropOptions | Constructor | Constructor[] };
  38. functional: boolean;
  39. render(this: never, createElement: $createElement, context: RenderContext): VNode;
  40. name?: string;
  41. }
  42. export interface RenderContext {
  43. props: any;
  44. children: VNode[];
  45. slots: any;
  46. data: VNodeData;
  47. parent: Vue;
  48. }
  49. export interface PropOptions {
  50. type?: Constructor | Constructor[] | null;
  51. required?: boolean;
  52. default?: any;
  53. validator?(value: any): boolean;
  54. }
  55. export interface ComputedOptions<V> {
  56. get?(this: V): any;
  57. set?(this: V, value: any): void;
  58. cache?: boolean;
  59. }
  60. export type WatchHandler<V> = (this: V, val: any, oldVal: any) => void;
  61. export interface WatchOptions {
  62. deep?: boolean;
  63. immediate?: boolean;
  64. }
  65. export type DirectiveFunction = (
  66. el: HTMLElement,
  67. binding: VNodeDirective,
  68. vnode: VNode,
  69. oldVnode: VNode
  70. ) => void;
  71. export interface DirectiveOptions {
  72. bind?: DirectiveFunction;
  73. inserted?: DirectiveFunction;
  74. update?: DirectiveFunction;
  75. componentUpdated?: DirectiveFunction;
  76. unbind?: DirectiveFunction;
  77. }