Created
October 17, 2017 02:20
-
-
Save wonderful-panda/1f8d7d190805bfebd230fd52cc4b945f to your computer and use it in GitHub Desktop.
apply additional types to vue component (for vue 2.5)
This file contains hidden or 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
| import Vue, { VNode, VNodeChildrenArrayContents } from "vue"; | |
| import { VueConstructor } from "vue/types/vue"; | |
| export function vueWith<T>(): VueConstructor<Vue & T> { | |
| return Vue as any; | |
| } | |
| export const TestComponent = vueWith<{ | |
| $refs: { test: HTMLDivElement }, | |
| $scopedSlots: { | |
| default: (props: { text: string }) => VNodeChildrenArrayContents | |
| } | |
| }>().extend({ | |
| name: "TestComponent", | |
| props: { | |
| text: String | |
| }, | |
| methods: { | |
| hello(): void { | |
| const html = this.$refs.test.innerHTML; | |
| console.log(html); | |
| } | |
| }, | |
| render(h): VNode { | |
| return h("div", { on: { click: this.hello }, ref: "test" }, | |
| this.$scopedSlots.default({ text: this.text }) | |
| ); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment