Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

defineComponentの書き方 #101

Closed
spaspa opened this issue Mar 3, 2020 · 10 comments
Closed

defineComponentの書き方 #101

spaspa opened this issue Mar 3, 2020 · 10 comments

Comments

@spaspa
Copy link
Member

spaspa commented Mar 3, 2020

#96 (comment)

@sapphi-red sapphi-red changed the title createComponentの書き方 defineComponentの書き方 Mar 9, 2020
@sapphi-red
Copy link
Member

#119 (comment)

@sapphi-red
Copy link
Member

vuejs/vue#9692

これが推奨っぽいです

@sapphi-red
Copy link
Member

defineComponentsに渡すオブジェクトのprops: {}は必須ではないので型のPropsを渡す方法もあるんですが、そっちだとveturが動いてくれないので上のやり方がよさそうです

@sapphi-red
Copy link
Member

あと上のやり方でやるとsetupでわざわざprops渡さなくても$propsで型情報使えますね

@sapphi-red
Copy link
Member

sapphi-red commented Apr 2, 2020

よく見たら$propsはPublicPropsでpropsはthis直下にあるみたいです(つまり、<template>内ではそのままで呼び出せる)
(ここのコメントと動作がかみ合ってない気がする)
https://github.com/vuejs/composition-api/blob/7c8386eea241974ead77d3fd3eb6916fa8903653/src/component/component.ts#L10-L22

@sapphi-red
Copy link
Member

    title: {
      type: String,
      default: ''
    },

があったときに<template>から$props.titleでアクセスするとstring | undefinedになってtitleでアクセスするとstringになります(上の実装からそうではあるんですが)

@sapphi-red
Copy link
Member

PublicPropsとは…?ってなってますが…

@sapphi-red
Copy link
Member

    currentNavigation: {
      type: String as PropType<NavigationItemType>,
      default: 'home' as const
    }

defaultをちゃんとas constなりas NavigationItemTypeなりしないと最終結果の型がstringに広がってしまうみたいです

@sapphi-red
Copy link
Member

vuejs/composition-api#146
こっちのissueを張ったほうがよかったですね

何か所か下のissueにひっかかるんですが、見た感じ割とすぐに直りそうです
vuejs/composition-api#291

@sapphi-red
Copy link
Member

上の方針で

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants