Utility Types
Вакансии vuejobs.com
Информация
This page only lists a few commonly used utility types that may need explanation for their usage. For a full list of exported types, consult the source code.
PropType<T>
Used to annotate a prop with more advanced types when using runtime props declarations.
Пример:
tsimport { PropType } from 'vue' interface Book { title: string author: string year: number } export default { props: { book: { // provide more specific type to `Object` type: Object as PropType<Book>, required: true } } }См. также: Guide - Typing Component Props
ComponentCustomProperties
Used to augment the component instance type to support custom global properties.
Пример:
tsimport axios from 'axios' declare module 'vue' { interface ComponentCustomProperties { $http: typeof axios $translate: (key: string) => string } }Совет
Augmentations must be placed in a module
.tsor.d.tsfile. See Type Augmentation Placement for more details.См. также: Guide - Augmenting Global Properties
ComponentCustomOptions
Used to augment the component options type to support custom options.
Пример:
tsimport { Route } from 'vue-router' declare module 'vue' { interface ComponentCustomOptions { beforeRouteEnter?(to: any, from: any, next: () => void): void } }Совет
Augmentations must be placed in a module
.tsor.d.tsfile. See Type Augmentation Placement for more details.См. также: Guide - Augmenting Custom Options
ComponentCustomProps
Used to augment allowed TSX props in order to use non-declared props on TSX elements.
Пример:
tsdeclare module 'vue' { interface ComponentCustomProps { hello?: string } } export {}tsx// now works even if hello is not a declared prop <MyComponent hello="world" />Совет
Augmentations must be placed in a module
.tsor.d.tsfile. See Type Augmentation Placement for more details.
CSSProperties
Used to augment allowed values in style property bindings.
Пример:
Allow any custom CSS property
tsdeclare module 'vue' { interface CSSProperties { [key: `--${string}`]: string } }tsx<div style={ { '--bg-color': 'blue' } }>html<div :style="{ '--bg-color': 'blue' }">Совет
Augmentations must be placed in a module
.tsor.d.tsfile. See Type Augmentation Placement for more details.См. также
SFC
<style>tags support linking CSS values to dynamic component state using thev-bindCSS function. This allows for custom properties without type augmentation.