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 {}
  }
}
最后修改:2022 年 01 月 25 日 12 : 25 AM
如果觉得我的文章对你有用,请随意赞赏