Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
levy committed Nov 11, 2020
2 parents 931b436 + 9dd82f0 commit 34b49d2
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
13 changes: 13 additions & 0 deletions docs/faq.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## 在 TypeScript 中指定组件的类型

```html
<script lang="ts">
// 需要引入这个
// import { LogViewerType } from '@femessage/log-viewer'
export default {
mounted() {
(this.$refs.logViewer as LogViewerType).autoScroll = false
},
}
</script>
```
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"browser": {
"./sfc": "src/log-viewer.vue"
},
"types": "src/log-viewer.d.ts",
"scripts": {
"dev": "vue-styleguidist server",
"test": "jest --verbose",
Expand Down
71 changes: 71 additions & 0 deletions src/log-viewer.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import Vue, {VueConstructor} from 'vue'

declare module '@femessage/log-viewer' {
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 LogViewerData = {
start: number
scrollStart: number
animate: any
LineWrapper: any
}

type LogViewerMethods = {}

type LogViewerComputed = {}

type LogViewerProps = {
virtualAttrs: object
rowHeight: number
height: number
log: string
loading: boolean
autoScroll: boolean
hasNumber: boolean
scrollDuration: number
}

type LogViewer = Combined<
LogViewerData,
LogViewerMethods,
LogViewerComputed,
LogViewerProps
>

export interface LogViewerType extends FemessageComponent, LogViewer {}

const LogViewerConstruction: ExtendedVue<
Vue,
LogViewerData,
LogViewerMethods,
LogViewerComputed,
LogViewerProps
>

export default LogViewerConstruction
}

0 comments on commit 34b49d2

Please sign in to comment.