Vue中props类型 设置默认值

Vue中props类型 设置默认值

props: {
    
    
  testString: {
    
    
    type: String,
    default: ''
  },
  testNumber: {
    
    
    type: Number,
    default: 0
  },
  testBoolean: {
    
    
    type: Boolean,
    default: true
  },
  testArray: {
    
    
    type: Array,
    default: () => []
  },
  testObject: {
    
    
    type: Object,
    default: () => ({
    
    })
  },
  testFunction: {
    
    
    type: Function,
    default: function () {
    
     }
  }
}

注意:当默认值为对象时不能写成

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

默认写法:

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

猜你喜欢

转载自blog.csdn.net/qq_58648235/article/details/130155921
今日推荐