-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
120 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
## 在 TypeScript 中指定组件的类型 | ||
|
||
```html | ||
<template> | ||
<v-img ref="vImg" :src="url" /> | ||
</template> | ||
<script lang="ts"> | ||
// 需要引入这个 | ||
// import { VImgType } from '@femessage/v-img' | ||
export default { | ||
data() { | ||
return { | ||
url: '' | ||
} | ||
}, | ||
mounted() { | ||
(this.$refs.vImg as VImgType).src = 'src' | ||
}, | ||
} | ||
</script> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import Vue from 'vue' | ||
|
||
declare module '@femessage/v-img' { | ||
class FemessageComponent extends Vue { | ||
static install(vue: typeof Vue): void | ||
} | ||
|
||
type CombinedVueInstance< | ||
Instance extends Vue, | ||
Data, | ||
Methods, | ||
Computed, | ||
Props | ||
> = Data & Methods & Computed & Props & Instance | ||
|
||
type ExtendedVue< | ||
Instance extends Vue, | ||
Data, | ||
Methods, | ||
Computed, | ||
Props | ||
> = VueConstructor< | ||
CombinedVueInstance<Instance, Data, Methods, Computed, Props> & Vue | ||
> | ||
|
||
type Combined<Data, Methods, Computed, Props> = Data & | ||
Methods & | ||
Computed & | ||
Props | ||
|
||
type VImgData = { | ||
isSupportWebp: boolean | null | ||
status: number | ||
transparentImg: string | ||
} | ||
|
||
type VImgMethods = { | ||
checkLayout: () => void | ||
|
||
checkSupportWebp: () => Promise<void> | ||
|
||
forceUpdateSrc: () => void | ||
|
||
onLoad: () => void | ||
|
||
onError: () => void | ||
|
||
onClick: () => void | ||
} | ||
|
||
type VImgComputed = { | ||
classname: string | ||
|
||
style: {[key: string]: any} | ||
|
||
imageSrc: any | ||
|
||
loadingImage: string | ||
|
||
reloadImage: string | ||
} | ||
|
||
type VImgProps = { | ||
src: string | ||
|
||
width: string | number | ||
|
||
height: string | number | ||
|
||
hasLoading: boolean | ||
|
||
provider: string | ||
|
||
extraQuery: string | ||
|
||
placeholder: string | ||
|
||
error: string | ||
|
||
autocrop: string | ||
} | ||
|
||
type VImg = Combined<VImgData, VImgMethods, VImgComputed, VImgProps> | ||
|
||
export interface VImgType extends FemessageComponent, VImg {} | ||
|
||
const VImgConstruction: ExtendedVue< | ||
Vue, | ||
VImgData, | ||
VImgMethods, | ||
VImgComputed, | ||
VImgProps | ||
> | ||
|
||
export default VImgConstruction | ||
} |