Vue中props類型及默認值


 props: {
    demoString: {
      type: String,
      default: ''
    },
    demoNumber: {
      type: Number,
      default: 0
    },
    demoBoolean: {
      type: Boolean,
      default: true
    },demoArray: {
      type: Array,
      default: () => []
    },
    demoObject: {
      type: Object,
      default: () => ({})
    },
    demoFunction: {
      type: Function,
      default: function () { }
    }
  }

其中,默認值為對象時
不能寫成

demoObject: {
      type: Object,
      default: () => { }
    }

不加’()'的話返回的是一個空函數體,沒有返回值。
默認寫法

demoObject: {
      type: Object,
      default: function () {
        return {}
      }
    }

 

訂閱專欄  props: {    demoString: {      type: String,      default: ''    },    demoNumber: {      type: Number,      default: 0    },    demoBoolean: {      type: Boolean,      default: true    },    demoArray: {      type: Array,      default: () => []    },    demoObject: {      type: Object,      default: () => ({})    },    demoFunction: {      type: Function,      default: function () { }    }  }1234567891011121314151617181920212223242526其中,默認值為對象時不能寫成
    demoObject: {      type: Object,      default: () => { }    }1234不加’()'的話返回的是一個空函數體,沒有返回值。默認寫法
    demoObject: {      type: Object,      default: function () {        return {}      }    }————————————————版權聲明:本文為CSDN博主「zhangyiyy」的原創文章,遵循CC 4.0 BY-SA版權協議,轉載請附上原文出處鏈接及本聲明。原文鏈接:https://blog.csdn.net/weixin_39457424/article/details/105289303


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM