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