vue3 props 声明默认值

interface ObjType {
    size: number,
    limit: number,
    auto: boolean
}
interface Props {
  msg?: string
  labels?: string[],
  obj: objType
}

const props = withDefaults(defineProps(), {
  msg: 'hello',
  labels: () => ['one', 'two'],
  obj: () => { return { size: 10, limit: 10, auto: false } }
 })
interface UploadObjType {
  size: Number
  limit: Number
  msg: any
  autoUpload: Boolean
  accept: String
  current?: String
}

const p = withDefaults(defineProps<{
  uploadObj: UploadObjType
}>(),{
  uploadObj: ()=>{
    return{
      size: 10,
      limit: 1,
      msg: 'any',
      autoUpload: true,
      accept: 'jpg',
      current: 'aaa'
    }
  }
})
const p = defineProps({
  uploadObj:{
    type: Object,
    default: ()=>{
      return{
      size: 101,
      limit: 1,
      msg: 'any',
      autoUpload: true,
      accept: 'jpg',
      current: 'aaa'
    }
    }
  }
})

你可能感兴趣的:(前端,javascript,开发语言)