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

posted @ 2022-01-24 16:21  王二疯  阅读(868)  评论(0编辑  收藏  举报