vue-composition-api

Props typing in Vue.js 3 with TypeScript

谁说胖子不能爱 提交于 2020-12-11 08:58:06
问题 I'm trying to type hint my props in a Vue 3 component, with composition API. So, I'm doing this: <script lang="ts"> import FlashInterface from '@/interfaces/FlashInterface'; import { ref } from 'vue'; import { useStore } from 'vuex'; export default { props: { message: { type: FlashInterface, required: true } }, setup(props): Record<string, unknown> { // Stuff } }; My FlashInterface looks like this: export default interface FlashInterface { level: string, message: string, id?: string } This

Strongly typing props of vue components using composition api and typescript typing system

你离开我真会死。 提交于 2020-12-02 05:11:24
问题 I am using vue composition api with typescript. How can I strongly type the component props using typescript typing system? 回答1: As explained in the official docs you can type props in two ways: Define arops via argument annotation import { defineComponent } from 'vue' export default defineComponent((props: { foo: string }) => { props.foo }) Or like this import { defineComponent } from 'vue' export default defineComponent({ props: { foo: String }, setup(props) { props.foo // <- type: string }

Strongly typing props of vue components using composition api and typescript typing system

北城余情 提交于 2020-12-02 05:08:13
问题 I am using vue composition api with typescript. How can I strongly type the component props using typescript typing system? 回答1: As explained in the official docs you can type props in two ways: Define arops via argument annotation import { defineComponent } from 'vue' export default defineComponent((props: { foo: string }) => { props.foo }) Or like this import { defineComponent } from 'vue' export default defineComponent({ props: { foo: String }, setup(props) { props.foo // <- type: string }

Strongly typing props of vue components using composition api and typescript typing system

你离开我真会死。 提交于 2020-12-02 05:06:52
问题 I am using vue composition api with typescript. How can I strongly type the component props using typescript typing system? 回答1: As explained in the official docs you can type props in two ways: Define arops via argument annotation import { defineComponent } from 'vue' export default defineComponent((props: { foo: string }) => { props.foo }) Or like this import { defineComponent } from 'vue' export default defineComponent({ props: { foo: String }, setup(props) { props.foo // <- type: string }

Strongly typing props of vue components using composition api and typescript typing system

百般思念 提交于 2020-12-02 05:06:40
问题 I am using vue composition api with typescript. How can I strongly type the component props using typescript typing system? 回答1: As explained in the official docs you can type props in two ways: Define arops via argument annotation import { defineComponent } from 'vue' export default defineComponent((props: { foo: string }) => { props.foo }) Or like this import { defineComponent } from 'vue' export default defineComponent({ props: { foo: String }, setup(props) { props.foo // <- type: string }