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

关于vue3.0-beta搭建开发环境 #4

Open
Mario34 opened this issue Jul 29, 2020 · 3 comments
Open

关于vue3.0-beta搭建开发环境 #4

Mario34 opened this issue Jul 29, 2020 · 3 comments

Comments

@Mario34
Copy link
Owner

Mario34 commented Jul 29, 2020

目前vue.3.x还处于beta状态,官方的英文文档v3.vuejs.org

使用tsx模式开发组件

尽管模版的写法一直是官方推荐的,除了没法支持类型提示,也没有可挑剔的了。这里选择TypeScript,所以采用tsx的模式代替template

为了实现tsx的加载,需要借助相关的loader插件 @ant-design-vue/babel-plugin-jsxHcySunYang/vue-next-jsx

@Mario34
Copy link
Owner Author

Mario34 commented Aug 3, 2020

vue-next jsx进展

尤大在关于vue/jsx的回复 vuejs/jsx/issues/141#issuecomment-658304273,尽可能少的添加语法糖到jsx中,因为选择使用jsx的用户未必一定使用模版语法

I've seen some great discussions here, while I don't have definitive answers to all the questions yet, I'll just write down some of my thoughts here:

  • I don't think we should add too much syntax sugar into JSX. If we do, we should do it in a type-safe and JSX-idiomatic fashion (i.e camelCase). For example I like the idea of vModel={[val, [modifiers]]}.

  • If we can agree on a type-safe usage for directives and event handlers, then I think we should later remove template-like syntax like v-on-click_stop, v-model_number or vModel_trim - they create extra complexities for typing, another way of doing things, plus JSX is for users who don't want to use templates anyway, so what's the point in making it look like templates?

在官方提供最新版本支持前、可以使用上面的两个社区的解决方案

@Mario34
Copy link
Owner Author

Mario34 commented Aug 3, 2020

期待vue jsx能够得到jsx官方的支持

jsx刚开始在react中对类型的支持也不好,后来react和ts团队合作再有了现在的完美支持。

Edit by @yyx990803 : there are currently two JSX transform implementations for Vue 3 with slightly differing syntax (for Vue specific features). We are using this thread to unify the design and land on an official specification of how Vue features should be handled in JSX.

希望能够得到jsx官方的支持

@Mario34
Copy link
Owner Author

Mario34 commented Aug 25, 2020

Vue3.x使用TypeScript

Vue对具有type定义的道具进行运行时验证。为了将这些类型提供给TypeScript,我们需要使用以下方法强制转换构造函数PropType:

import { defineComponent, PropType } from 'vue'

interface ComplexMessage {
  title: string
  okMessage: string
  cancelMessage: string
}
const Component = defineComponent({
  props: {
    name: String,
    success: { type: String },
    callback: {
      type: Function as PropType<() => void>
    },
    message: {
      type: Object as PropType<ComplexMessage>,
      required: true,
      validator(message: ComplexMessage) {
        return !!message.title
      }
    }
  }
})

https://v3.vuejs.org/guide/typescript-support.html#annotating-return-types

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

1 participant