vue3.x+Ts组件封装

Posted 朱丽叶

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vue3.x+Ts组件封装相关的知识,希望对你有一定的参考价值。

// 1
    import { defineComponent, PropType } from "vue"
    import { IFromItem } from "./types"

    props: {
        fromItem: {
          // 给传递过来的数据进行类型限制  需要在vue中引入PropType 重新断言为自己设置的类型。
          type: Array as PropType<IFromItem[]>,
          // 在vue+ts中props给定默认值为数组或者对象时,使用箭头函数
          default: () => []
        },
        labelWidth: {
          type: String,
          default: "100px"
        },
      },

// 2. 定义数据类型
    export interface IFromItem {
      label: string
      type: "input" | "password" | "select" | "datepicker"
      placeholder?: string
      // 针对select
      options?: any[]
      // 针对特殊的属性
      otherOptions?: any
    }

以上是关于vue3.x+Ts组件封装的主要内容,如果未能解决你的问题,请参考以下文章

利用渲染函数,实现动态创建弹窗-Vue3.X

利用渲染函数,实现动态创建弹窗-Vue3.X

Vuepress 文档脚手架(vue 3.x+vuepress2.x+vite+ts)

简单对比vue2.x与vue3.x响应式及新功能

【vue3.x+vite】.ts文件识别不了.vue 文件

vue+Ts+element组件封装