Vue中組件之間傳值 props類型及默認值


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 () { }
    }
  }

注意:默認值為對象時 需要寫成:default: () => ({}) 不加'()'的話返回的是一個空函數體,沒有返回值

參考:https://blog.csdn.net/weixin_39457424/article/details/105289303


免責聲明!

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



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