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
    }


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM